link_to send parameters along with the url and grab them on target page

后端 未结 2 1212
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 11:24

How can i have a link on a page that takes the user to another URL and passes along a parameter and on the target url how can we pick up that parameter.

usually I ad

2条回答
  •  Happy的楠姐
    2020-12-04 12:10

    Here's a more rails-y way of doing it.

    <%= link_to 'Link Text', 
    {controller: 'controller/name', action: 'action_name', query: params[:query]},
    method: 'get', 
    :class=>'link_styling' %>
    

    You need to reference your params in the hash defining the link. It also needs to be a GET method. Styling is optional of course.

    This should really be here too: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

提交回复
热议问题