Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use Railties for initializing plugin #192

Closed
smoothcontract opened this issue Sep 28, 2011 · 27 comments
Closed

Use Railties for initializing plugin #192

smoothcontract opened this issue Sep 28, 2011 · 27 comments

Comments

@smoothcontract
Copy link

We use this plugin with Rails 3.1 but due to the way the plugin initializes itself we get an error whilst running the 'rake assets:precompile' task on deployment to Heroku.

Essentially the plugin forces ActiveRecord to be loaded during initialization, which in turn forces a database connection to be attempted. This probably doesn't matter that much when deploying elsewhere but Heroku builds a 'slug' with all the precompiled assets - at which point the database connection isn't available.

See: http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting

If the initialization stuff could be rewritten to use Railties it would work nicely on Heroku. Will_paginate is a nice example of this.

Cheers!

@tonydaly
Copy link

  • 1 on this issue

@smoothcontract
Copy link
Author

@BobWalsh - The plugin works on Heroku but it breaks the asset precompilation stage (for asset pipeline) of deployment which means Heroku has to fall back to dynamically generated assets which are slower.

This happens if a plugin attempts to load ActiveRecord during initialization (Rails made some changes to minimise this but acts as taggable is still affected). The reference to ActiveRecord forces the DB connection to be attempted - which fails as Heroku hasn't configured the database connection at that stage of the deployment.

If I disable acts as taggable plugin then the assets are precompiled cleanly.

@artemk
Copy link
Collaborator

artemk commented Dec 12, 2011

@smoothcontract pull request is welcome.

@smoothcontract
Copy link
Author

@artemk Fair enough - I'll give it a go when I get some time available

@WizardOfOgz
Copy link

I'm using a hack to work around the issue with act as taggable until it is fixed.

acts_as_taggable rescue nil # HACK: there is a known issue that acts_as_taggable breaks asset precompilation on Heroku.

@dwaynemac
Copy link

+1 on this and
@WizardOfOgz , where do you put that line?

@chalofa
Copy link

chalofa commented Feb 3, 2012

+1 with the problem (and also the work around, thanks @WizardOfOgz )

@WizardOfOgz
Copy link

@dwaynemac I use that in each model that I want to make taggable

@urkle
Copy link

urkle commented Feb 26, 2012

from the Ruby on Rails guides they mention a workaround for the heroku issue with some gems

http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

Basically you set config.assets.initialize_on_precompile to false.

@tilsammans
Copy link
Contributor

Would this problem be fixed if this plugin is moved to an engine structure?

@eamo
Copy link

eamo commented May 31, 2013

+1 With problem (and the workaround is not working on Rails 4.0.0rc1)

@trappist
Copy link

trappist commented Aug 2, 2013

+1 on the problem and the workaround on 4.0.0

@dcabo
Copy link

dcabo commented Aug 4, 2013

+1 on this. Just ran into this issue deploying a Rails 4.0 / Ruby 2.0 app onto Heroku. The config.assets.initialize_on_precompile setting doesn't fix it, but enabling an Heroku Labs experimental feature does: heroku labs:enable user-env-compile. More info.

@jcamenisch
Copy link

Would it not be better to use acts_as_taggable if connection.active? rather than eating all exceptions with rescue nil?

Note: I haven't tested this yet; just wondering if someone here has a reason for ruling that out.

@ericboehs
Copy link

I tried several different combinations of checking if the connection was present/active. Unfortunately this doesn't work:
acts_as_taggable if -> { defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.active? }

I guess for now I'm justing going to rescue nil and pray all is well.

@jcamenisch
Copy link

Well, I guess we have our answer.

Maybe you should post a comment on the acts_as_taggable thread just to keep
someone else from trying all that stuff.
On Aug 7, 2013 11:43 PM, "Eric Boehs" notifications@github.com wrote:

I tried several different combinations of checking if the connection was
present/active. Unfortunately this doesn't work:
acts_as_taggable if -> { defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.active? }

I guess for now I'm justing going to rescue nil and pray all is well.


Reply to this email directly or view it on GitHubhttps://github.com//issues/192#issuecomment-22301604
.

@jackdempsey
Copy link

hey folks, FWIW you can prevent this issue without a blanket rescue nil by doing:
unless ARGV.join.include? 'assets:precompile'
acts_as_taggable_on
end

@ericboehs
Copy link

Thanks! Nicer hack!

On Thu, Aug 29, 2013 at 10:35 PM, jack dempsey notifications@github.com
wrote:

hey folks, FWIW you can prevent this issue without a blanket rescue nil by doing:
unless ARGV.join.include? 'assets:precompile'
acts_as_taggable_on

end

Reply to this email directly or view it on GitHub:
#192 (comment)

@jcamenisch
Copy link

Indeed

@Linuus
Copy link

Linuus commented Sep 3, 2013

@jackdempsey That doesn't work for me as it seems to choke when Heroku does assets:clean instead. Had to go for rescue nil for now :(

@adamrubin
Copy link

@Linuus Just do something like:

  unless (ARGV.join.include? 'assets:precompile') || (ARGV.join.include? 'assets:clean')
    acts_as_taggable_on :foo
  end

@anatomic
Copy link

@adamrubin and @jackdempsey Thanks for posting your updated ways around this, it's been bugging me for the last couple of days!

@markburns
Copy link

  unless (ARGV & ['assets:precompile', 'assets:clean']).any?
    acts_as_taggable_on :foo
  end

@rcuyegkeng
Copy link

@markburns Thanks for providing a workaround for this problem.

@markburns
Copy link

@rcuyegkeng I can't take credit - I just reworded @adamrubin 's solution

bumi referenced this issue in EuroHackTrip/eurohacktrip.org Dec 19, 2013
@bf4
Copy link
Collaborator

bf4 commented Dec 26, 2013

Should be fixed by #438

@bf4 bf4 closed this as completed Dec 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests