GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
The code on 3-2-stable is very different but It should be an easy fix too.
`asset_path` respects SCRIPT_NAME.
remove trailing whitespace
@steveklabnik @guilleiguaran can you take a look?
if respond_to?(:request) should be enough?
I saw this pattern down below: https://github.com/senny/rails/blob/83613ca60b1d536003a58839cd878a0fd8673be3/actionpack/lib/action_view/helpers/asset_url_helper.rb#L195
I'm not sure the request method can actually return nil
Yes, it returns nil for ActionMailer, for example.
I guess we should keep it the way it is then. If this PR makes it in, I'd like to perform a quick cleanup/refactoring on the that helper code.
I am afraid this will cause unintended side effects. If you have a mountable engine, the script_name will also be set but in this case, asset_path still should not consider script path because the entity responsible for delivering assets is in the main application (sprockets in this case).
So I think we should create a mountable engine and ensure we can still access its assets after this patch. Things can get even trickier, because you have can have a mountable engine with Passenger's script_name and in this case we should use only the one coming from passenger. Here are a couple places to look at:
As far as I can tell AC still has a relative_url_root option but I think this won't fix the problem. If I interpret this test correctly: https://github.com/rails/rails/blob/master/actionpack/test/template/asset_tag_helper_test.rb#L558-L573
That option is already considered when computing the asset path and it won't be set when you change the rack mount point.
@senny you're meant to set config.relative_url_root to the same as the mount point for the application. IIRC, the original intention for Rails 3.0 was to deprecate it and the environment variable RAILS_RELATIVE_URL_ROOT and use SCRIPT_NAME exclusively. However it was undeprecated because of the need to be able get the relative url root outside of a request context like precompiling assets.
I think we need to have a CF chat about the various options and come up with a plan for sorting this out.
@pixeltrix thanks for clarifying. I put my work on hold and catch you on CF.
I'm closing this one as this is not a viable solution. I'm working on a different approach.