{"action":"opened","issue":{"url":"https://api.github.com/repos/rails/rails/issues/23019","labels_url":"https://api.github.com/repos/rails/rails/issues/23019/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/23019/comments","events_url":"https://api.github.com/repos/rails/rails/issues/23019/events","html_url":"https://github.com/rails/rails/issues/23019","id":126048488,"number":23019,"title":"request<ActionDispatch::Request> is spookingly altered when invoking a url helper method within views under specific circumstances","user":{"login":"Rev3rse","id":3087191,"avatar_url":"https://avatars.githubusercontent.com/u/3087191?v=3","gravatar_id":"","url":"https://api.github.com/users/Rev3rse","html_url":"https://github.com/Rev3rse","followers_url":"https://api.github.com/users/Rev3rse/followers","following_url":"https://api.github.com/users/Rev3rse/following{/other_user}","gists_url":"https://api.github.com/users/Rev3rse/gists{/gist_id}","starred_url":"https://api.github.com/users/Rev3rse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rev3rse/subscriptions","organizations_url":"https://api.github.com/users/Rev3rse/orgs","repos_url":"https://api.github.com/users/Rev3rse/repos","events_url":"https://api.github.com/users/Rev3rse/events{/privacy}","received_events_url":"https://api.github.com/users/Rev3rse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-11T22:08:24Z","updated_at":"2016-01-11T22:08:24Z","closed_at":null,"body":"Hello everyone,\r\nI think I've found a spooky bug in Rails `~> 5.0.0.beta1`( last commit 179df9df6839 ).\r\n**The code below worked perfectly fine on Rails `~> 4.2.0`**\r\n\r\nConsider this dead simple `erb` view, under specific circumstances(which I will outline below), the `request<ActionDispatch::Request>` instance variable is changed, simply by invoking `root_path`:\r\n```erb\r\n# Before invoking root_path, the value of request.path_parameters is:\r\n# request.path_parameters = {.. action: action_1 ..}\r\n\r\n# An innocent call:\r\n<% root_path %>\r\n\r\n# AFTER invoking root_path, the value of request.path_parameters is:\r\n# notice that the action value changed from :action_1 to :index\r\n# request.path_parameters = {.. action: **index**  ..}\r\n\r\n# EXAMPLE:\r\n#url_for is using request.parameters under the hood to build its options; hence it's completely\r\n# inaccurate now(it points to index action or crashes when it does not exist; instead of action_1)\r\n\r\n<%= url_for(locale: :ar) %>\r\n# UrlGenerationError: No route matches {:action=>\"index\", :controller=>\"custom\", :locale=>:ar}\r\n\r\n```\r\n\r\nReproduction:\r\n===========\r\n\r\n`Gemfile`:\r\n\r\n```Ruby\r\n\r\nsource 'https://rubygems.org'\r\n\r\nruby '2.3.0'\r\n\r\n# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'\r\ngem 'rails', github: 'rails/rails' #last commit 179df9d at the time of writing\r\n\r\ngem 'sqlite3'\r\n\r\ngroup :development, :test do\r\n  # Call 'byebug' anywhere in the code to stop execution and get a debugger console\r\n  gem 'byebug'\r\nend\r\n\r\ngroup :development do\r\n  gem 'web-console', '~> 3.0'\r\n  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring\r\n  gem 'spring'\r\nend\r\n\r\n# Windows does not include zoneinfo files, so bundle the tzinfo-data gem\r\ngem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\r\n\r\n\r\n```\r\n\r\n`routes.rb`:\r\n\r\n```ruby\r\nRails.application.routes.draw do\r\n\r\n\r\n  scope \"/:locale\", locale: /en|ar/ do\r\n\r\n    root \"application#index\"\r\n\r\n    get 'action_1' => 'custom#action_1'\r\n  end\r\nend\r\n\r\n```\r\n\r\n`custom_controller.rb`:\r\n```ruby\r\nclass CustomController < ActionController::Base\r\n\r\n  def action_1\r\n  end\r\n\r\nend\r\n```\r\n\r\n`custom/action_1.html.erb`:\r\n```erb\r\n\r\n# original (expected) value of request here...\r\n<%= root_path %>\r\n\r\n# modified (unexpected) value of request\r\n\r\n# unexpected URL is generated here, since action the key used internally by #url_for is index and not action_1\r\n<%= url_for(locale: :ar) %>\r\n\r\n# Error raised by #url_for in this example:\r\n# ActionController::UrlGenerationError in Custom#action_1: No route matches {:action=>\"index\", :controller=>\"custom\", :locale=>:ar}\r\n\r\n```\r\n\r\nBlind Workaround: \r\n==============\r\n\r\n**Although the root path is being defined within a scope, which makes no sense; the bug itself could possibly point to a deeper problem, especially that it did not exist in Rails 4.2**\r\nFor those of us who have to use Rails 5 awesomeness while this bug is still alive and kicking, I found a blind workaround for this, simply move out the `    root \"application#index\" ` outside the scope block, and the bug will magically disappear.\r\n\r\nnew `routes.rb`:\r\n```ruby\r\nRails.application.routes.draw do\r\n\r\n  root \"application#index\"\r\n\r\n  scope \"/:locale\", locale: 'en' do\r\n\r\n\r\n    get 'action_1' => 'custom#action_1'\r\n  end\r\nend\r\n\r\n```"}}