简体   繁体   中英

Rails: Add params in link_to

I need 2 params to controll the view. Something like http://localhost:3000/products?display=table&range=month

在此处输入图片说明

So user can select view by month/week , or display by thumbnail/table

How can I do something like link_to current_url, range: 'month' , so the generated link based on current params? So it can append &range=month to http://localhost:3000/products?display=thumbnail .

I may not be quite clear in this description, so if you have any problem, just ask and I'll update.

In one app I added to Application helper followin method

def repeat_current_params
   params.except(:controller, :action)
end

Then in view you might call link_to 'Name', repeat_current_params.merge(additional_param_key: 'its_value')

您可以像这样添加参数<%= link_to "Html text", <x>_path({param: value, param2, value2}) %>或链接到当前页面, <%= link_to "Html text", {param1: value1, param2: value2} %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM