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
Reported by MCW BBC | December 10th, 2008 @ 09:27 PM | in 2.x
When I deploy my application, the first POST request causes the javascript_include_tag to fail with a nil object error for expand_sources. Additional requests do not trigger the error.
On line #5 of app/views/layouts/application.html.erb
2: <html xmlns="http://www.w3.org/1999/xhtml">
3: <title>SNPlotyper</title>
4: <%= stylesheet_link_tag :all, :cache => true %>
5: <%= javascript_include_tag :all, :cache => true %>
6: <script type="text/javascript" charset="utf-8">
7: var $jq = jQuery.noConflict();
8: </script>
gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:744:in `tag_sources'
gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:748:in `joined_contents'
gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `write_asset_file_contents'
gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `open'
gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:717:in `write_asset_file_contents'
gems/actionpack-2.2.2/lib/action_view/helpers/asset_tag_helper.rb:253:in `javascript_include_tag'
app/views/layouts/application.html.erb:5
Comments and changes to this ticket
-
Frederick Cheung December 11th, 2008 @ 12:07 AM
- 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 December 11th, 2008 @ 02:59 PM
- 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:4
This 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:5
The 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 December 11th, 2008 @ 03:25 PM
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 December 11th, 2008 @ 05:54 PM
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 December 22nd, 2008 @ 03:49 AM
- Assigned user set to Frederick Cheung
-
Frederick Cheung December 23rd, 2008 @ 12:45 AM
Can you condense this into a small example (ie actual code)?
-
Frederick Cheung January 4th, 2009 @ 06:36 PM
A lot of the asset tag stuff was changed in 104898f. Has that changed anything for you?
-
jgeiger January 5th, 2009 @ 02:28 PM
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 March 10th, 2009 @ 11:07 AM
- State changed from new to stale
Putting on "stale". Please reopen if it's still an issue.
Thanks.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>