Skip to content

Instantly share code, notes, and snippets.

@radar
Created December 18, 2010 11:11
Show Gist options
  • Save radar/746414 to your computer and use it in GitHub Desktop.
Save radar/746414 to your computer and use it in GitHub Desktop.
/2/admin/users/2/edit
i.e.
/user_id/admin/users/user_id/edit
This should error with a "No route matches" error because there's not enough parameters handed to the helper. It's not.
scope :path => ":account_id" do
namespace :admin do
resources :users
end
end
<%= puts edit_admin_user_path(@user) %>
<%= link_to "Edit", edit_admin_user_path(@user) %>

Now try this:

git clone git://github.com/rails3book/ticketee
cd ticketee
git checkout origin/account_scoping -b account_scoping
bundle install
bundle exec cucumber features/assigning_permissions.feature:32

You should get the same non-error that I am. This is the only way I can reproduce this issue.

@alindeman
Copy link

Looks like ActionDispatch::Routing::RouteSet#handle_positional_args is deciding to assign :account_id from the User object. :id is also somehow assigned from the User object. I didn't investigate too much further here.

@pixeltrix
Copy link

What's going on is that handle_positional_args is assigning the :account_id from the user object and the :id parameter is being filled from the request's path parameters. The permissions url fails to generate because :user_id is not in the path parameters for the show action. Using hash arguments generates both urls correctly as :account_id is filled from the path parameters. e.g:

<%= link_to "Delete", admin_user_path(:id => @user), :method => :delete, :confirm => "Are you sure you want to delete this user?" %>
<%= link_to "Permissions", admin_user_permissions_path(:user_id => @user) %>

@pacso
Copy link

pacso commented Dec 18, 2010

Free books all round? Or do we have to share? lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment