如何使用 Rails 2 上的 POST 发送 link_to 参数

发布于 2024-12-08 20:22:40 字数 532 浏览 0 评论 0 原文

我有一个像这样的 link_to :

<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => @hotel_id, :selected_tab => "4"}, :class => "new_link" %>

有一种方法可以发送这些参数而不使用查询字符串吗? (使用 post 而不是 get)?

谢谢你!

我已经尝试过了:

<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => @hotel_id, :selected_tab => "4"}, {:method => :post,:class => "new_link"}  %>

而且它一直在做同样的事情......!

I have a link_to like this:

<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => @hotel_id, :selected_tab => "4"}, :class => "new_link" %>

There's a way to send those parameters not using the query string for it? (using post instead of a get) ??

Thank you!

I already tried:

<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => @hotel_id, :selected_tab => "4"}, {:method => :post,:class => "new_link"}  %>

And it keeps doing the same thing...!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-柠檬树下少年和吉他 2024-12-15 20:22:40

在方法选项中添加受支持的 HTTP 谓词。

<%= link_to "link", {:method =>; :post ...} %>

Add a supported HTTP verb in the method option.

<%= link_to "link", {:method => :post ...} %>

捎一片雪花 2024-12-15 20:22:40

我认为你只需添加 :method =>; :postlink_to 的选项。

以下是文档(适用于 Rails 3,但我认为这也适用于 Rails 2) http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

编辑更新的问题

:方法=> :post 属于 HTML 选项,而不是 URL 选项。从文档来看这不是很明显。

<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => @hotel_id, :selected_tab => "4"}, {:method => :post, :class => "new_link"}  %>

I think you can just add :method => :post to the options of link_to.

Here are the docs (for Rails 3, but I think this still holds true for Rails 2 also) http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

EDIT FOR UPDATED QUESTION

:method => :post belongs in the HTML options, not the URL options. This is not very obvious from the documentation.

<%= link_to "Nuevo Contrato", {:controller => "hotels", :action => "edit", :id => @hotel_id, :selected_tab => "4"}, {:method => :post, :class => "new_link"}  %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文