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
ActionView::Helpers::AssetUrlHelper#asset_path uses request.script_name in an engine #8119
Comments
Code is here https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/asset_url_helper.rb#L135-139 I never understood the point of adding the script name. I'd rather just get rid of it and make engines responsible for namespacing their assets if thats what they actually want to do. |
I will need to look at the history of this file, I think that I originally used |
Also ran into this problem today. Commit 8e26d29 (#910 / #5296) seems to have introduced the 5b3bb61 may be related - dunno - all around Rack's SCRIPT_NAME env var. Perhaps the scenario outlined in #910 is slightly at odds with the Rails engine scenario -- or perhaps asset pipeline needs to be able to take these cases into account. My head is too dull right now to connect any dots - but if any of this helps, figured I'd put it here. |
@guilleiguaran could you take a look at this one? |
Sorry for being quiet for so long, I agree with others here ( |
I'm having a bit of trouble with the fix for this issue. I'm using a plain rails app, with no engines mounted on subdirectories (at least I think so, I'm not 100% sure about terminology here). However, the entire application is mounted on a subdirectory, which nginx correctly passes to Rails in the SCRIPT_NAME variable. For regular links this works as expected, the SCRIPT_NAME gets prepended to all links within the application. However, for assets, this does not work, it generates /assets/foo instead of /subdir/assets/foo. If I revert the commit referenced above, everything works again as expected. I realize I can fix this by setting As far as I understand things, the original problem was that, inside a mounted engine, request.script_name would include the mount point, resulting in incorrect urls for assets inside such a mounted engine. In other words, inside a mounted engine, request.script_name would be incorrect for generating assets urls. Therefore, the above commit stops using request.script_name altogether. AFAICS, a better fix would be to always use the script_name originally passed by the webserver and Rack, even in a mounted engine. In that way, all assets would use the original script_name and get the correct url. I'm fairly new to Rails so I can't really comment on how to achieve this, though. Does this make sense? |
@matthijskooijman the problem is that |
Ah, you're saying that the asset compilation happens on startup instead of on-demand during the first request, so you don't know what SCRIPT_NAME will be? |
No, asset compilation (for production) either happens as part of the deployment process or offline via Basically, assets are under a single global namespace - typically /assets but can be configured to something else. The code that was removed assumed individual namespaces for each engine, e.g. /assets and /blog/assets which was the original method of using static files from individual engines. |
rails/rails@445f14e (e.g. to deal with jasmine-rails spec/assets paths)
rails/rails@445f14e (e.g. to deal with jasmine-rails spec/assets paths)
backporting fix to rails/rails#8119 from
I encountered the following problem with current master branch (4.0.0.beta):
The asset_path method seems to use the
request.script_name
information to determine the correct url for the assets.But when you try to include assets per
assets_path
in an engine (or a depending method e.g.stylesheet_link_tag
) than thisscript_name
is prefixed to the urls.Steps to reproduce:
foo#bar
which uses a layout.Gemfile
mount Blorgh::Engine, :at => 'blorgh'
Problem: The stylesheet-link url is generates
I temporarily fix this problem by setting
config.relative_url_root = ''
inapplication.rb
of the main project.The text was updated successfully, but these errors were encountered: