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

Info about precompile assets on Heroku with custom config #34

Closed
wyaeld opened this issue Sep 25, 2012 · 5 comments
Closed

Info about precompile assets on Heroku with custom config #34

wyaeld opened this issue Sep 25, 2012 · 5 comments

Comments

@wyaeld
Copy link
Contributor

wyaeld commented Sep 25, 2012

Hi Les, it turns out the quirks of the assets precompile stage on Heroku can make things a little tricky if you are using HandlebarsAssets to customize the compiler. I thought I'd share the findings, and maybe you could include a note in the docs to make life easier for others.

This is not a bug of any sort, just sharing info gained.

The issue is while in "development" putting the following in an initialiser or config

HandlebarsAssets::Config.options = { data: true }

works perfectly fine, but they won't compile that way on Heroku if you aren't precompiling prior to pushing, because Heroku's compile step runs prior, and usually most people have

config.assets.initialize_on_precompile = false

and HandlebarsAssets is usually in the "assets" group in Gemfile, so not available in Production

My solution is to add a form of the following:

if "assets" == ENV["RAILS_GROUPS"] || ["development", "test"].include?(ENV["RAILS_ENV"])
  HandlebarsAssets::Config.options = { data: true }
end

Now assets:precompile under every scenario I've encountered compiles with the custom options. Hope this is useful.

@noiseunion
Copy link

Thanks for posting this! Helped me out big time!

@leshill
Copy link
Owner

leshill commented Nov 21, 2012

Hi @wyaeld,

Added a link here in the README.

Thanks!

@leshill leshill closed this as completed Nov 21, 2012
@eddietejeda
Copy link

The explanation here is unclear.

if "assets" == ENV["RAILS_GROUPS"] || ["development", "test"].include?(ENV["RAILS_ENV"])
  HandlebarsAssets::Config.options = { data: true }
  HandlebarsAssets::Config.template_namespace = 'JST'
end

Adding the code on top to config/initializers/ or config/enviroments/production.rb does not seem to work. I finally got it working on Heroku after I added the snippet to to application.rb

@wyaeld
Copy link
Contributor Author

wyaeld commented May 13, 2013

Hi Eddie, sorry it wasn't clear enough.

The way that Heroku interacts with the assets pipeline means the compile step is actually happening before the app is aware that its it production, so as you will have noticed, adding it to the production.rb isn't enough.

Your solution is correct, its in my config/application.rb

Unfortunately we might need an alternative for Rails4. According to Ryan here
http://railscasts.com/episodes/415-upgrading-to-rails-4
The assets gems no longer have to be in the "assets" group, which may interfere with it. Right now I'm not working on a Rails4 app and don't really have the time to test that theory

@simondelorean
Copy link

Thanks for posting! Works great. I'm using handlebars with ember right now, so I had to add one more line:
if "assets" == ENV["RAILS_GROUPS"] || ["development", "test"].include?(ENV["RAILS_ENV"])
HandlebarsAssets::Config.options = { data: true }
HandlebarsAssets::Config.ember = true
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants