Search code examples
ruby-on-railsformtastic

How to force the method for a formtastic form to be put?


I have something like

semantic_form_for @whatever, :url => whatever_url

which generates a from with

method="post"

I need it to be put, I've already tried:

semantic_form_for @whatever, :url => whatever_url, :html => {:method => "put"}

and

semantic_form_for @whatever, :url => whatever_url, :html => {:method => :put}

and

semantic_form_for @whatever, :url => whatever_url, :html_args => {:method => :put}

with no effect. Any ideas how it's done?


Solution

  • Is it generating a form that looks something like this?

    <form action="..." method="POST">
    ...
    

    If so, then it's probably still creating a PUT request. Rails determines the POST, PUT or DELETE request by using the _method attribute instead. The best way to verify that this is working is to check your logs to see that a PUT request is coming through. You can also force this to happen by adding a hidden attribute to your form like this:

    <input type="hidden" name="_method" value="put" />