开发者

Simulate PUT on a link, in Rails3

开发者 https://www.devze.com 2023-02-08 03:34 出处:网络
So far, I know that in Rails I can simulate a PUT request using a form which has a hidden input with name=\'_method\' and value=\'put\', but I\'m interested in simulating that for a link.

So far, I know that in Rails I can simulate a PUT request using a form which has a hidden input with name='_method' and value='put', but I'm interested in simulating that for a link.

How can I have a link in a view that would fit this route:

match '/article/:id/publ开发者_StackOverflowish', :to => 'article#publish', :via => :put


The docs for link_to say you can specify a :method option that creates a form that is submitted on clicking the link.

link_to "Publish!", publish_article_path(article), :method => :put

Not sure what your route helper method would be (I assumed publish_article_path - you should be able to figure it out with rake routes from the command line. The :method is the important part that will do the magic you want.

0

精彩评论

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