Question

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/publish', :to => 'article#publish', :via => :put
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top