Skip to content

Instantly share code, notes, and snippets.

@radar
Created December 18, 2010 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.

@pjb3
Copy link

pjb3 commented Dec 18, 2010

I do get this error:

No route matches {:account_id=>#<User id: 1, name: "Paul", created_at: "2010-12-18 12:25:04", updated_at: "2010-12-18 12:25:04">, :controller=>"admin/users", :action=>"edit"}

@pacso
Copy link

pacso commented Dec 18, 2010

The only substantial difference I can see is the parameter argument names:
edit_admin_user GET /:account_id/admin/users/:id/edit(.:format) {:action=>"edit", :controller=>"admin/users"}
admin_user_permissions GET /:account_id/admin/users/:user_id/permissions(.:format) {:action=>"index", :controller=>"admin/permissions"}

Could edit_admin_user be working simply because it's picking up the :id param and using it for both arguments. admin_user_permission is looking for :user_id and failing.

Only thing I can come up with.

@alindeman
Copy link

I think pasco is on to something, yes.

@alindeman
Copy link

grumble Trying to break on the call to the URL helper is segfaulting the 1.9.2 debugger for me. Will see if 1.8.7 works better.

@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