views:

619

answers:

2

I have a resource defined in routes.rb like so:

map.resources :users

I like using the cleanest link_to option, which would be:

link_to @user

I'd like to add an additional parameter to this call, though: "view=local"

If I were using the user_path, I'd do this:

link_to user_path(@user, { :view => 'local' })

Is there a way to get the same result without including the user_path function explicitly? Ideally, I'd do something like:

link_to @user, { :view => 'local' }

but that doesn't seem to work.

+3  A: 

No, you can't. The only real control you have is the ability to add more params on the link tag. link_to has a third parameter that would let you add things like a title attribute on the HTML tag, but it's not going to modify the href value.

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597

Go ahead and use the user_path helper. As with most things in Rails, if you want to do the default action, it's going to be simple. You want to do something more complex, so you have to do more work :)

Tim Rosenblatt
+2  A: 

This should work:

link_to @user.name, user_path(@user, :view => "local")
Kieran Hayes