Rails: How to add an additional parameter for link_to link to a resource?

I have a resource defined in routes.rb as follows:

map.resources :users

I like to use the cleanest link_to parameter, which would be the following:

link_to @user

I would like to add an additional parameter to this call: "view = local"

If I used user_path, I would 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 would do something like:

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

but it does not work.

+3
source share
1 answer

, . , , - . link_to , , title HTML, href.

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

user_path. Rails, , . - , :)

+5

Source: https://habr.com/ru/post/1733568/


All Articles