简体   繁体   中英

Rails pass params dynamic by using link_to

I am stuck, maybe it's just a silly question. There's a sort button, I need to use it to sort my question list.

What I do is that, I create a link_to like

<%= link_to xx_path(:is_sort => true, :remote=> true , :method=> :post %>

Then the controller will do sorting, respond_to sort_question.js.erb and render a sort question list.

But when I click the sort button again, I need to render the original question list.

So maybe :is_sort => true became :is_sort => false dynamically.

I've tried to use Jquery ajax, but it will return text instead of script . Furthermore, according to this Answer , this way may cause security issue.

BTW, I don't want to sort in front-end because this question list do a lot of actions like create, delete or edit.

如果尚未单击is_sort则将is_sort设置为true ;将is_sort单击时, is_sort将设置为false

xx_path(:is_sort => !params[:is_sort])

试试这个

<%= link_to xx_path(:is_sort => true), :remote => true %>

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