开发者

How to send link_to parameters using POST on Rails 2

开发者 https://www.devze.com 2023-04-11 06:30 出处:网络
I have a link_to like this: <%= link_to \"Nuevo Contrato\", {:controller => \"hotels\", :action => \"edit\", :id => @hotel_id, :selected_tab => \"4\"}, :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" %>

The开发者_运维知识库re'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...!


Add a supported HTTP verb in the method option.

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


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"}  %>
0

精彩评论

暂无评论...
验证码 换一张
取 消