{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/12178","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/12178/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/12178/comments","events_url":"https://api.github.com/repos/rails/rails/issues/12178/events","html_url":"https://github.com/rails/rails/issues/12178","id":19216016,"number":12178,"title":"Regression in rails 4 when generating routes with optional scope","user":{"login":"deivid-rodriguez","id":2887858,"avatar_url":"https://avatars.githubusercontent.com/u/2887858?v=3","gravatar_id":"","url":"https://api.github.com/users/deivid-rodriguez","html_url":"https://github.com/deivid-rodriguez","followers_url":"https://api.github.com/users/deivid-rodriguez/followers","following_url":"https://api.github.com/users/deivid-rodriguez/following{/other_user}","gists_url":"https://api.github.com/users/deivid-rodriguez/gists{/gist_id}","starred_url":"https://api.github.com/users/deivid-rodriguez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deivid-rodriguez/subscriptions","organizations_url":"https://api.github.com/users/deivid-rodriguez/orgs","repos_url":"https://api.github.com/users/deivid-rodriguez/repos","events_url":"https://api.github.com/users/deivid-rodriguez/events{/privacy}","received_events_url":"https://api.github.com/users/deivid-rodriguez/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/regression","name":"regression","color":"e10c02"},{"url":"https://api.github.com/repos/rails/rails/labels/routing","name":"routing","color":"e102d8"}],"state":"open","locked":false,"assignee":{"login":"pixeltrix","id":6321,"avatar_url":"https://avatars.githubusercontent.com/u/6321?v=3","gravatar_id":"","url":"https://api.github.com/users/pixeltrix","html_url":"https://github.com/pixeltrix","followers_url":"https://api.github.com/users/pixeltrix/followers","following_url":"https://api.github.com/users/pixeltrix/following{/other_user}","gists_url":"https://api.github.com/users/pixeltrix/gists{/gist_id}","starred_url":"https://api.github.com/users/pixeltrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pixeltrix/subscriptions","organizations_url":"https://api.github.com/users/pixeltrix/orgs","repos_url":"https://api.github.com/users/pixeltrix/repos","events_url":"https://api.github.com/users/pixeltrix/events{/privacy}","received_events_url":"https://api.github.com/users/pixeltrix/received_events","type":"User","site_admin":false},"assignees":[{"login":"pixeltrix","id":6321,"avatar_url":"https://avatars.githubusercontent.com/u/6321?v=3","gravatar_id":"","url":"https://api.github.com/users/pixeltrix","html_url":"https://github.com/pixeltrix","followers_url":"https://api.github.com/users/pixeltrix/followers","following_url":"https://api.github.com/users/pixeltrix/following{/other_user}","gists_url":"https://api.github.com/users/pixeltrix/gists{/gist_id}","starred_url":"https://api.github.com/users/pixeltrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pixeltrix/subscriptions","organizations_url":"https://api.github.com/users/pixeltrix/orgs","repos_url":"https://api.github.com/users/pixeltrix/repos","events_url":"https://api.github.com/users/pixeltrix/events{/privacy}","received_events_url":"https://api.github.com/users/pixeltrix/received_events","type":"User","site_admin":false}],"milestone":null,"comments":16,"created_at":"2013-09-09T19:02:22Z","updated_at":"2016-07-28T09:36:43Z","closed_at":null,"body":"Hi! I just upgraded one application to rails 4 and I'm getting an error I didn't expect. I'm sorry if I'm missing something and this is an intentional change.\r\n\r\nWhen there's an optional scope, `link_to resource` doesn't seem to work properly in rails 4. I can change every link to `link_to resource_path(id: resource.id)` but that's a lot of links to change and that kind of shortcut seemed nice and readable...\r\n\r\nTo reproduce copy and paste the following into a terminal\r\n\r\n    rails new optional_scope_routes_rails4\r\n    cd optional_scope_routes_rails4\r\n    rails generate scaffold post title body:text published:boolean\r\n    rake db:migrate\r\n    echo 'Post.create(title: \"Hi\", body: \"Hello\", published: false)' | rails c\r\n    cat <<EOF > config/routes.rb\r\n    OptionalScopeRoutesRails4::Application.routes.draw do\r\n      scope '(:locale)', locale: /en|es/  do\r\n        resources :posts\r\n        root 'posts#index'\r\n      end\r\n    end\r\n    EOF\r\n    cat <<EOF > app/controllers/application_controller.rb\r\n    class ApplicationController < ActionController::Base\r\n      protect_from_forgery\r\n      before_filter :set_locale\r\n\r\n      private\r\n        def set_locale\r\n          I18n.locale = params[:locale] || I18n.default_locale\r\n          Rails.application.routes.default_url_options[:locale] = I18n.locale\r\n        end\r\n    end\r\n    EOF\r\n    rails s\r\n    \r\n\r\nWhen I open the browser at `0.0.0.0:3000` I get the error\r\n    \r\n    No route matches {:controller=>\"posts\", :action=>\"show\", :locale=>#<Post id: 1, title: \"Hi\", body: \"Hello\", published: false, created_at: \"2013-09-09 18:44:45\", updated_at: \"2013-09-09 18:44:45\">, :id=>nil, :format=>nil} missing required keys: [:id]\r\n\r\nin `optional_scope_routes_rails4/app/views/posts/index.html.erb` line `#21`\r\n\r\n    <td><%= link_to 'Show', post %></td>\r\n\r\nBut in rails3 it works just fine... Open another terminal and try it with the following\r\n\r\n    rails _3.2.14_ new optional_scope_routes_rails3\r\n    cd optional_scope_routes_rails3\r\n    rails generate scaffold post title body:text published:boolean\r\n    rake db:migrate\r\n    echo 'Post.create(title: \"Hi\", body: \"Hello\", published: false)' | rails c\r\n    cat <<EOF > config/routes.rb\r\n    OptionalScopeRoutesRails3::Application.routes.draw do\r\n      scope '(:locale)', locale: /en|es/  do\r\n        resources :posts\r\n        root :to => 'posts#index'\r\n      end\r\n    end\r\n    EOF\r\n    cat <<EOF > app/controllers/application_controller.rb\r\n    class ApplicationController < ActionController::Base\r\n      protect_from_forgery\r\n      before_filter :set_locale\r\n\r\n      private\r\n        def set_locale\r\n          I18n.locale = params[:locale] || I18n.default_locale\r\n          Rails.application.routes.default_url_options[:locale] = I18n.locale\r\n        end\r\n    end\r\n    EOF\r\n    rm public/index.html\r\n    rails s -p3001\r\n    \r\n\r\nThanks a lot in advance!"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/235847405","html_url":"https://github.com/rails/rails/issues/12178#issuecomment-235847405","issue_url":"https://api.github.com/repos/rails/rails/issues/12178","id":235847405,"user":{"login":"DamodarSojka","id":6706539,"avatar_url":"https://avatars.githubusercontent.com/u/6706539?v=3","gravatar_id":"","url":"https://api.github.com/users/DamodarSojka","html_url":"https://github.com/DamodarSojka","followers_url":"https://api.github.com/users/DamodarSojka/followers","following_url":"https://api.github.com/users/DamodarSojka/following{/other_user}","gists_url":"https://api.github.com/users/DamodarSojka/gists{/gist_id}","starred_url":"https://api.github.com/users/DamodarSojka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DamodarSojka/subscriptions","organizations_url":"https://api.github.com/users/DamodarSojka/orgs","repos_url":"https://api.github.com/users/DamodarSojka/repos","events_url":"https://api.github.com/users/DamodarSojka/events{/privacy}","received_events_url":"https://api.github.com/users/DamodarSojka/received_events","type":"User","site_admin":false},"created_at":"2016-07-28T09:36:43Z","updated_at":"2016-07-28T09:36:43Z","body":"Is this bug still present in rails 4.2? Or has it been fixed? Is there a solution that does not require updating to 5.0.0?"}}
{"actor":{"display_login":"DamodarSojka"}}