-
Notifications
You must be signed in to change notification settings - Fork 247
Rails.application.assets is nil in production #237
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
Comments
Thats right.
So it sounds like using those gems may have been behaving poorly in production before. |
Yeah. That looks right to me too. @kirs do you know why the gem is doing that? |
@rafaelfranca that is They do it inside lambda, but it's still being called in production with |
ISTM the ideal would be for us to provide an That way we could help people ignore implementation details (that, IMO, they shouldn't need to care about) like where on the filesystem the assets actually live -- basically providing a more-suitably-shaped API around just using File.read. |
It seems like this is being fixed on the react-rails side. |
Sprockets Rails now unset `Rails.application.assets` when `config.assets.compile` is false, causing an issue as we were relying on that hash. The workaround here is to read the manifest file directly by using `Sprockets::Railtie.build_manifest`. Also adding Rails 4.2 using Sprockets Rails 2.3 to the build matrix. See issue rails/sprockets-rails#237 for more detail. Fix #12
Sprockets Rails now unset `Rails.application.assets` when `config.assets.compile` is false, causing an issue as we were relying on that hash. The workaround here is to read the manifest file directly by using `Sprockets::Railtie.build_manifest`. Note that this patch requires the manifest file to exists, so you have to run `rake assets:precompile` to generate the manifest file first. Also adding Rails 4.2 using Sprockets Rails 2.3 to the build matrix. See issue rails/sprockets-rails#237 for more detail. Fix #12
Sprockets Rails now unset `Rails.application.assets` when `config.assets.compile` is false, causing an issue as we were relying on that hash. The workaround here is to read the manifest file directly by using `Sprockets::Railtie.build_manifest`. Note that this patch requires the manifest file to exists, so you have to run `rake assets:precompile` to generate the manifest file first. Also adding Rails 4.2 using Sprockets Rails 2.3 to the build matrix. See issue rails/sprockets-rails#237 for more detail. Fix #12
Rails.application.assets is nil in production rails/sprockets-rails#237 Rails.application.assets is Nil on Heroku after upgrade sprockets-rails to 3.0.0 http://stackoverflow.com/questions/34380753/rails-application-assets-is-nil-on-heroku-after-upgrade-sprockets-rails-to-3-0-0
Just as the reference for people trying to fix it in the local codebase after the update. The easy fix is to replace |
matfiz, thank you very much for the helpful workaround. |
Hello, my approach is different. I need to use compiled asset inline on production.
On my old Rails 4.2 app this works fine in both development and production. On my new Rails 5 app this only works on development. An additional information: My new App runs on Heroku |
I got to work with the following code
It is very ugly but for now was I could think |
Thanks @rafaelfranca. Rails.application.assets_manifest.find_sources('asset.js').first seems to return exactly what Rails.application.assets['asset.js'].to_s used to produce and it works both in dev and prod :) |
And doesn't compile the asset in production. |
Thanks @rafaelfranca @fxtentacle that works for me! |
@fxtentacle your solution worked great for me, thanks. I had to modify it slightly by putting And then in production.rb
|
If you are looking for an exact replacement for |
@nasa42 "Sprockets::Error: manifest requires environment for compilation" which makes it sound like it's trying to recompile... |
@nzifnab Sorry, we are no longer using that line in our app, so I don't have any more information about it. |
FYI I needed to find files that are not part of the manifest ... so switching to looking through gem dirs instead: # clunky asset finder ... see https://github.com/rails/sprockets-rails/issues/237 for more
# jquery.js -> <GEM_HOME>/ruby/2.3.0/gems/rails-assets-jquery-2.2.1/app/assets/javascripts/jquery.js
def resolve_javascript(file)
paths = Gem::Specification.stubs.map(&:full_gem_path)
Dir.glob("{#{paths.join(",")}}/app/assets/javascripts/#{file}").first || raise("Could not find #{file}")
end |
We needed to access a compiled file within another file during precompilation, so We solved this by doing this: Sprockets::Railtie.build_environment(Rails.application, true)[file_name].to_s In case anyone is in the same situation that we are. |
Followed suggestion at rails/sprockets-rails#237 (comment)
According to this comment (rails/sprockets-rails#237 (comment)), the committed changed here is the exact replacement for the previously used method.
In sprockets v3, when running the rails application in production mode, `Rails.application.assets` returns nil (see: rails/sprockets-rails#237). The result of this returning nil would mean that when the layout file is executed by the ruby interpreter, it would attempt to call `[]` on `nil`, which results in the page 500ing.
In sprockets v3, when running the rails application in production mode, `Rails.application.assets` returns nil (see: rails/sprockets-rails#237). The result of this returning nil would mean that when the layout file is executed by the ruby interpreter, it would attempt to call `[]` on `nil`, which results in the page 500ing.
This will compile every time while sending the mail which is not ideal but at least this appears to work after upgrading to rails 5 rails/sprockets-rails#237 (comment)
I found ways to check for assets in both development and production (heroku) in Rails 5.2, but neither works in both environments, so I added an application helper like this:
Now I can check if an image_exists in both production and development before calling image_tag. The root of the problem is image_tag throws an exception if the image doesn't exist....why not just respond nil??? |
En production, quand l'asset pipeline est désactivé (config.assets.compile = false), les assets peuvent être retrouvés avec la propriété `Rails.application.assets_manifest`. rails/sprockets-rails#237 (comment)
En production, quand l'asset pipeline est désactivé (config.assets.compile = false), les assets peuvent être retrouvés avec la propriété `Rails.application.assets_manifest`. rails/sprockets-rails#237 (comment)
Now in
sprockets-rails
3app.assets
is set only in case whenassets.compile
option is enabled (https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L142).By default in Rails this option is set to
false
in production environment: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt#L27This leads us to the bug when some gem calls
Rails.application.assets.resolve("asset.js")
in production environment and the NoMethodError is raised.@josh does it sounds like a bug?
The text was updated successfully, but these errors were encountered: