Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid db connection on application boot #98

Merged
merged 4 commits into from
Oct 21, 2011
Merged

Avoid db connection on application boot #98

merged 4 commits into from
Oct 21, 2011

Conversation

jswanner
Copy link
Contributor

awesome_nested_set can prevent rake assets:precompile from successfully running. In what seems like a esoteric condition -- a database not existing and a class using awesome_nested_set being loaded on application boot -- is a very real possibility now on heroku combined with Rails 3.1's rake assets:precompile, especially if you are using something like Refinery CMS, or a Rails engine that you do not control the code.

To reproduce:

A model (could be from an engine or something):

class Category < ActiveRecord::Base
  acts_as_nested_set
end

And in config/application.rb:

config.to_prepare do
  Category.class_eval do
    def to_s
      title
    end
  end
end

Then run RAILS_ENV=env_with_no_db rake assets:precompile -- or deploy to heroku -- and you will see assets are not being precompiled.

This should prevent "rake assets:precompile" from failing on heroku in certain conditions.
This might not be the best change, as the columns are now exposed; but, having attr_protected it here causes 'rake assets:precompile' to crash if the class is loaded on app boot.  Perhaps it's best to suggest the use of attr_accessible.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants