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
Malformed asset url when rendering a view partial with ActionController::Renderer #28151
Comments
This seems to be a problem with
I'm thinking this might be addressed with a separate implementation of module ActionDispatch
class Request
def scheme
super || protocol.gsub("://", "")
end
end
end WDYT @rafaelfranca? If you're good with this solution, I can open a PR. |
@Erol : Researching the problem by myself, I also reached the The fact is that when rendering a partial with the "traditional" way we get the correct So I am thinking that instead of 'patching' the scheme method inside This is just a theoretical approach, I don't know what the limitations are, so excuse me for any mistakes! |
Come to think of it, this can also be addressed by setting: config.action_controller.asset_host = "http://my.assets.com" |
Configuration with The only problem is that someone must add this line manually inside
and uncomment this line inside
So this is not very "convention over configuration"! I did a deeper research and I came across the following solution. I put a byebug inside
So that's it! Why don't we add more parameters into Finally my solution looks like this:
WDYT @rafaelfranca and @Erol ? |
Added a PR for review! #28250 |
If the API is going to be changed - a parameter was dropped - I think at the very least a deprecation notice should be served.
I have a different opinion on this. Similar to |
I agree that
Sorry I don't understand exactly which API do you mean. So at your opinion we must write additional tests in order to check if existing parameters are valid or check parameters validity inside the actual class during runtime? |
I think I wasn't able to make my point clear. The default behavior as it stands is not entirely correct, malformed URL or not. I doubt anyone is using example.org as their host. 😉 But of course, the malformed URL being generated by
You're proposing a change on how new renderers are instantiated, such that |
I agree 100%. Parameter
You are absolutely right, I haven't thought about that scenario. I just made an additional commit on my merge request. Thanks again for your advice! |
Fixed by merging #28250 |
I am facing an issue with malformed url of assets when rendering a partial template through ActionController::Renderer.
This partial contains the following code:
<%= asset_url('noavatar.jpg') %>
or it can be<%= path_url('noavatar.jpg') %>
Now open a rails console and run the following code:
ApplicationController.render(partial: 'shared/test')
You will get the following result:
Notice that not only the protocol inside the url is malformed but also we are getting and a non relevant 80 port.
Now lets set the https parameter to true
renderer = ApplicationController.renderer.new(https: true)
renderer.render(partial: 'shared/test')
Now everything seems to be working perfectly!
Notice: This malfunction is not happening with normal page urls. For example if you insert the following code inside 'test' partial:
<%= url_for(action: 'index', controller: 'products', only_path: false) %>
and run in console once again
ApplicationController.render(partial: 'shared/test')
you will get the expected result
System configuration
Rails version: 5.1.0.beta1
Ruby version: 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
The text was updated successfully, but these errors were encountered: