我的网站页面上有 3 个链接列表,应该更改那里的参数。链接是:
ul
li = link_to "View all", coasters_path
ul
li
- if params[:type] == "steel"
- params.delete :type
= link_to "Steel", coasters_path(params)
- else
= link_to "Steel", coasters_path(params.merge({type: "steel"}))
li
- if params[:type] == "wood"
- params.delete :type
= link_to "Wooden", coasters_path(params)
- else
= link_to "Wooden", coasters_path(params.merge({type: "wood"}))
li
- if params[:type] == "powered"
-params.delete :type
= link_to "Powered", coasters_path(params)
- else
= link_to "Powered", coasters_path(params.merge({type: "powered"}))
ul
li
- if params[:letters] == "#"
- params.delete :letters
= link_to "#", coasters_path(params)
- else
= link_to "#", coasters_path(params.merge({letters: "#"}))
li
- if params[:letters] == "a-e"
- params.delete :letters
= link_to "A-E", coasters_path(params)
- else
= link_to "A-E", coasters_path(params.merge({letters: "a-e"}))
li
- if params[:letters] == "f-j"
- params.delete :letters
= link_to "F-J", coasters_path(params)
- else
= link_to "F-J", coasters_path(params.merge({letters: "f-j"}))
li
- if params[:letters] == "k-o"
- params.delete :letters
= link_to "K-O", coasters_path(params)
- else
= link_to "K-O", coasters_path(params.merge({letters: "k-o"}))
li
- if params[:letters] == "p-t"
- params.delete :letters
= link_to "P-T", coasters_path(params)
- else
= link_to "P-T", coasters_path(params.merge({letters: "p-t"}))
li
- if params[:letters] == "u-z"
- params.delete :letters
= link_to "U-Z", coasters_path(params)
- else
= link_to "U-Z", coasters_path(params.merge({letters: "u-z"}))
问题是,如果我重新访问该页面,coasters_path
或者/coasters
单击 Steel 链接,那很好,所以参数是 ?type=steel。但是,然后我单击 AE,参数会删除 type=steel 并将其替换为 letters=ae。
如果我以相反的方式执行此操作并先执行 AE,然后执行 Steel,它会添加 ?letters=ae,然后将 &type=steel 连接到末尾,从而链接过滤器。
知道为什么会发生这种情况以及如何解决吗?我只是看不到代码有任何问题吗?