This project is archived and is in readonly mode.
javascript_include_tag throwing nil object error on first load after deploy when used with cache in production
-
Frederick Cheung
- Tag changed from 2.2.2, asset_tag_helper, expand_sources, javascript_include_tag to 2.2.2, asset_tag_helper, expand_sources, javascript_include_tag, patch
I think this should fix it.
-
jgeiger
- Tag changed from 2.2.2, asset_tag_helper, expand_sources, javascript_include_tag, patch to 2.2.2, assets_dir, asset_tag_helper, patch, rails.public_path
This doesn't fix the issue, but it did lead me to do some more testing.
If I run it on my dev box in production mode, the first GET request works properly, and will create /public/javascripts/all.js and /public/stylesheets/all.js
The first POST request will fail with the following error:
Errno::ENOENT in Analyses#visualize Showing app/views/layouts/application.html.erb where line #4 raised: No such file or directory - ./public/stylesheets/standard.css /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:561:in `read' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:561:in `contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `joined_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `collect' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `joined_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `write_asset_file_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `open' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `write_asset_file_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:393:in `stylesheet_link_tag' /Users/me/workspace/webapp/app/views/layouts/application.html.erb:4This will also now create the new file:
/public/images/public/stylesheets/all.cssRun the same POST request again, and it creates:
/public/images/public/javascripts/all.jsIt also throws this error/trace:
Errno::ENOENT in Analyses#visualize Showing app/views/layouts/application.html.erb where line #5 raised: No such file or directory - ./public/javascripts/prototype.js /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:561:in `read' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:561:in `contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `joined_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `collect' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `joined_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `write_asset_file_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `open' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `write_asset_file_contents' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:253:in `javascript_include_tag' /Users/me/workspace/webapp/app/views/layouts/application.html.erb:5The third POST request is then successful.
It seems that somewhere along the way ASSETS_DIR or Rails.public_path are getting messed up and it's redefined on the POST requests, which cause the cached stylesheets and javascripts to be placed in a weird area.
line 104 of asset_tag_helper.rb
ASSETS_DIR = defined?(Rails.public_path) ? Rails.public_path : "public" -
Frederick Cheung
So what i did was change a uniq! to a uniq (because the return value of uniq! is nil if nothing as removed).
A separate issue it would seem is that :all tries to collect all the js that rails assume are there (ie prototype, scriptaculous etc...) and which I'm guessing you;re not using and may even have removed
-
jgeiger
I'm using all of the default js files, and some others as well. What my further research showed above is that there is something wrong with where the cached files are being created on my POST request. It looks like the ASSETS_DIR is being set to public from inside the images directory, which is odd. It's like Rails.public_path is being reset in some way.
-
Pratik
- Assigned user set to Frederick Cheung
-
Frederick Cheung
Can you condense this into a small example (ie actual code)?
-
Frederick Cheung
A lot of the asset tag stuff was changed in 104898f. Has that changed anything for you?
-
jgeiger
I'm not using edge, but I would have to believe this will fix it.
This line that was removed is very telling to me since my all.js and all.css ended up getting stuck into the images folder after requests.
- module ImageAsset
- DIRECTORY = 'images'.freeze
-
Pratik
- State changed from new to stale
Putting on "stale". Please reopen if it's still an issue.
Thanks.
