{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/28151","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/28151/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/28151/comments","events_url":"https://api.github.com/repos/rails/rails/issues/28151/events","html_url":"https://github.com/rails/rails/issues/28151","id":210074639,"number":28151,"title":"Malformed asset url when rendering a view partial with ActionController::Renderer","user":{"login":"tzabaman","id":22303333,"avatar_url":"https://avatars2.githubusercontent.com/u/22303333?v=3","gravatar_id":"","url":"https://api.github.com/users/tzabaman","html_url":"https://github.com/tzabaman","followers_url":"https://api.github.com/users/tzabaman/followers","following_url":"https://api.github.com/users/tzabaman/following{/other_user}","gists_url":"https://api.github.com/users/tzabaman/gists{/gist_id}","starred_url":"https://api.github.com/users/tzabaman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzabaman/subscriptions","organizations_url":"https://api.github.com/users/tzabaman/orgs","repos_url":"https://api.github.com/users/tzabaman/repos","events_url":"https://api.github.com/users/tzabaman/events{/privacy}","received_events_url":"https://api.github.com/users/tzabaman/received_events","type":"User","site_admin":false},"labels":[{"id":107189,"url":"https://api.github.com/repos/rails/rails/labels/actionpack","name":"actionpack","color":"FFF700","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/rails/rails/milestones/49","html_url":"https://github.com/rails/rails/milestone/49","labels_url":"https://api.github.com/repos/rails/rails/milestones/49/labels","id":1601639,"number":49,"title":"5.1.0","description":"","creator":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars0.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":49,"state":"open","created_at":"2016-02-24T03:19:34Z","updated_at":"2017-03-01T21:18:51Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2017-02-24T15:18:28Z","updated_at":"2017-03-01T22:32:50Z","closed_at":null,"body":"I am facing an issue with malformed url of assets when rendering a partial template through ActionController::Renderer.\r\n\r\n1. Put an image inside app/assets/images folder, let's name it noavatar.jpg\r\n2. Create a _test.text.erb partial under app/views/shared folder (shared is a new folder)\r\n\r\nThis partial contains the following code:\r\n`<%= asset_url('noavatar.jpg') %>` or it can be `<%= path_url('noavatar.jpg') %>`\r\n\r\nNow open a rails console and run the following code:\r\n\r\n`ApplicationController.render(partial: 'shared/test')`\r\n\r\nYou will get the following result:\r\n\r\n> http://://example.org:80/assets/noavatar-04b48dfebdd9a9ec5971b22b3bfe8144c04e2de8909adbb5a52897a881dea8df.jpg\r\n\r\nNotice that not only the protocol inside the url is malformed but also we are getting and a non relevant 80 port.\r\n\r\nNow lets set the https parameter to true\r\n\r\n`renderer = ApplicationController.renderer.new(https: true)`\r\n`renderer.render(partial: 'shared/test')` \r\n\r\nNow everything seems to be working perfectly!\r\n\r\n> https://example.org/assets/noavatar-04b48dfebdd9a9ec5971b22b3bfe8144c04e2de8909adbb5a52897a881dea8df.jpg\r\n\r\nNotice: This malfunction is not happening with normal page urls. For example if you insert the following code inside 'test' partial:\r\n\r\n`<%= url_for(action: 'index', controller: 'products', only_path: false) %>`\r\n\r\nand run in console once again\r\n\r\n`ApplicationController.render(partial: 'shared/test')`\r\n\r\nyou will get the expected result\r\n\r\n> http://example.org/products\r\n\r\n### System configuration\r\n**Rails version**: 5.1.0.beta1\r\n\r\n**Ruby version**: 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/283492995","html_url":"https://github.com/rails/rails/issues/28151#issuecomment-283492995","issue_url":"https://api.github.com/repos/rails/rails/issues/28151","id":283492995,"user":{"login":"tzabaman","id":22303333,"avatar_url":"https://avatars2.githubusercontent.com/u/22303333?v=3","gravatar_id":"","url":"https://api.github.com/users/tzabaman","html_url":"https://github.com/tzabaman","followers_url":"https://api.github.com/users/tzabaman/followers","following_url":"https://api.github.com/users/tzabaman/following{/other_user}","gists_url":"https://api.github.com/users/tzabaman/gists{/gist_id}","starred_url":"https://api.github.com/users/tzabaman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzabaman/subscriptions","organizations_url":"https://api.github.com/users/tzabaman/orgs","repos_url":"https://api.github.com/users/tzabaman/repos","events_url":"https://api.github.com/users/tzabaman/events{/privacy}","received_events_url":"https://api.github.com/users/tzabaman/received_events","type":"User","site_admin":false},"created_at":"2017-03-01T22:32:50Z","updated_at":"2017-03-01T22:32:50Z","body":"Configuration with `config.action_controller.asset_host` seems to be working. \r\n\r\nThe only problem is that someone must add this line manually inside \r\n> config/environments/development.rb\r\n\r\nand uncomment this line inside\r\n\r\n> config/environments/production.rb\r\n\r\nSo this is not very \"convention over configuration\"!\r\n\r\nI did a deeper research and I came across the following solution. \r\n\r\nI put a byebug inside `Rack::Request#scheme`. Running the following code from console when the execution stopped: `env.keys.map{ |k| \"#{k} => #{env[k]}\" }` I instantly realized that the env variable is way more richer when let's say a partial is being parsed with the \"traditional\" way. On the other hand when a partial is being parsed via `ApplicationController.render` the env variable contains only the following keys:\r\n\r\n```\r\nHTTP_HOST => example.org,\r\nHTTPS => off,\r\nREQUEST_METHOD => GET,\r\nSCRIPT_NAME => ,\r\nrack.input => ,\r\naction_dispatch.routes => #<ActionDispatch::Routing::RouteSet:0x000000017c2828>,\r\naction_controller.instance => #<ApplicationController:0x00000003f25a78>\r\n```\r\n\r\nSo that's it! Why don't we add more parameters into `ActionController::Renderer#env` when instantiating it?\r\n\r\nFinally my solution looks like the this\r\n\r\n```\r\nmodule ActionController\r\n  class Renderer\r\n\r\n    DEFAULTS = {\r\n      http_host: \"example.org\",\r\n      # https: false, # WE DON'T NEED THIS LINE ANY MORE\r\n      method: \"get\",\r\n      script_name: \"\",\r\n      input: \"\",\r\n      url_scheme: \"http\" # <-- THIS LINE ADDED\r\n    }.freeze\r\n\r\n    private\r\n\r\n      RACK_KEY_TRANSLATION = {\r\n        http_host:   \"HTTP_HOST\",\r\n        # https:       \"HTTPS\", # WE DON'T NEED THIS LINE ANY MORE\r\n        method:      \"REQUEST_METHOD\",\r\n        script_name: \"SCRIPT_NAME\",\r\n        input:       \"rack.input\",\r\n        url_scheme:  \"rack.url_scheme\" # <-- THIS LINE ADDED\r\n      }\r\n\r\n  end\r\nend\r\n```\r\nWDYT @rafaelfranca  and @Erol ?"}}
{"actor":{"display_login":"tzabaman"}}