When I push my Rails 4 application to Heroku, it generates an "assets:precompile rake task" failure:
remote: Running: rake assets:precompile
remote: rake aborted!
remote: NameError: uninitialized constant ValidatesTimeliness
It appears Heroku is unable to precompile the assets, because of an issue with the gem "ValidatesTimeliness." Based on Heroku's documentation on the Rails 4 asset pipeline, I ran
RAILS_ENV=production bundle exec rake assets:precompile
to see if the problem also occurs in my local environment. It does; I got the same error locally.
Here's the contents of my config/intializers/validates_timeliness.rb file:
ValidatesTimeliness.setup do |config|
# Extend ORM/ODMs for full support (:active_record, :mongoid).
# config.extend_orms = [ :active_record ]
#
# Default timezone
# config.default_timezone = :utc
#
# Set the dummy date part for a time type values.
# config.dummy_date_for_time_type = [ 2000, 1, 1 ]
#
# Ignore errors when restriction options are evaluated
# config.ignore_restriction_errors = false
#
# Re-display invalid values in date/time selects
# config.enable_date_time_select_extension!
#
# Handle multiparameter date/time values strictly
# config.enable_multiparameter_extension!
#
# Shorthand date and time symbols for restrictions
# config.restriction_shorthand_symbols.update(
# :now => lambda { Time.current },
# :today => lambda { Date.current }
# )
#
# Use the plugin date/time parser which is stricter and extendable
# config.use_plugin_parser = false
#
# Add one or more formats making them valid. e.g. add_formats(:date, 'd(st|rd|th) of mmm, yyyy')
# config.parser.add_formats()
#
# Remove one or more formats making them invalid. e.g. remove_formats(:date, 'dd/mm/yyy')
# config.parser.remove_formats()
#
# Change the amiguous year threshold when parsing a 2 digit year
# config.parser.ambiguous_year_threshold = 30
#
# Treat ambiguous dates, such as 01/02/1950, as a Non-US date.
# config.parser.remove_us_formats
end
Here's the contents of my gem file:
source 'https://rubygems.org'
gem 'rails', '4.1.8'
gem 'bootstrap-sass', '~> 3.2.0.0'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :development do
gem 'spring'
gem 'simple_form'
gem 'bcrypt', '~> 3.1.7'
end
group :development, :test do
gem 'pg'
gem 'rspec-rails', '~> 3.1.0'
gem 'factory_girl_rails'
gem 'validates_timeliness', '~> 3.0'
gem 'validates_overlap'
end
group :test do
gem 'byebug'
gem 'capybara', '~> 2.4.3'
gem 'shoulda-matchers', '~> 2.7.0'
gem 'faker'
gem 'paper_trail', '~> 3.0.6'
gem 'database_cleaner', '~> 1.3.0'
gem 'launchy', '~> 2.4.2'
gem 'rspec-activemodel-mocks'
gem 'selenium-webdriver', '~> 2.43.0'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
My hunch is I may need to do something in validates_timeliness set-up file, but I'm not sure what to do, because the rake failure relates to a "NameError." I'd appreciate any advice and guidance on how I should proceed.
In your Gemfile you've declared the validates_timeliness gem in a development group.
In Production it isn't installed, so you are getting an error. Try moving the validates_timeliness gem out of the group or, if you only need it in development, surround your initializer code with:
if Rails.env.development?
ValidatesTimeliness.setup do |config|
end
end