主页

rails link_to post

2023-09-08 10:51AM

参考:https://stackoverflow.com/questions/13414663/using-rails-link-to-for-links-that-post

方法1:

如果你是要查询参数,那么这将起作用:

link_to "Profile", profile_path(@profile.id, param1: 'value1', param2: 'value2'), method: :post

 方法2:

你可以通过以下方式对URL中的参数进行修改:(如果它不符合你的需求,你最好使用表格而不是链接。)

link_to "Profile", 'http://example.com/profile?' + {param1: 'value1', param2: 'value2'}.to_param, method: :post

Rails button_to助手:

button_to 'Profile', profile_path(@profile, param1: 'value1', param2: 'value2')

button_to 还支持 method 选项,但默认为 post 所以我这里省略了它。

Rails 7:

link_to "Profile", profile_path(@profile), data: { turbo_method: "post" }

 参数和http方法在一起使用:{param1:“value1”,param2:“value2”,:method::post}

<%= link_to "Profile", profile_path(@profile), {param1: 'value1', param2: 'value2', method: :post} %>

返回>>

登录

请登录后再发表评论。

评论列表:

目前还没有人发表评论