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

Rails.application.assets is nil in production even during precompilation #407

Closed
mrsimo opened this issue Jun 15, 2017 · 3 comments
Closed

Comments

@mrsimo
Copy link

mrsimo commented Jun 15, 2017

First of all, I'm aware of #237 and I think I understand the reasoning. I wanted to explain our use case and see if it makes sense.

We have a situation where we want to embed a platform.css inside a platform.js. For this, in Rails 4 we used <%= Rails.application.assets['platform.css'].to_s %>. We can't switch to Rails.application.assets_manifest.find_sources because the platform.css isn't there the very first time you run assets:precompile.

We solved this issue by initializing a sprockets environment, using:

Sprockets::Railtie.build_environment(Rails.application, true)['platform.css'].to_s

Even though assets.compile is false, I would have expected that Rails.application.assets is available during the assest:precompile rake task. It is the production environment, but it's also the precompilation task.

I wonder if you'd reconsider this use case and if we can find an alternative. Thanks.

@rafaelfranca
Copy link
Member

rafaelfranca commented Jun 15, 2017

Does using the public API <%= depend_on_asset('platform.css').source %> works?

@mrsimo
Copy link
Author

mrsimo commented Jun 15, 2017

Oh, my. Had no idea depend_on_asset existed. It seems to work! Apologies for the noise and thanks for the solution!

@mrsimo mrsimo closed this as completed Jun 15, 2017
@rafaelfranca
Copy link
Member

No problem 😄. You can see all methods on that context here http://www.rubydoc.info/gems/sprockets/Sprockets/Context

dariusbakunas added a commit to dariusbakunas/font-awesome-rails-base64 that referenced this issue Oct 18, 2019
In Rails 4.2 Rails.application.assets is nil during precompile step
rails/sprockets-rails#407
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

2 participants