views:

508

answers:

3

On edit.html.erb file, scaffold created, I don't see any code specified PUT method. How come the post form call update action with PUT method.

A: 

The standard Rails way to handle updates is to have an edit template (your edit.html.erb), which generates a form that is filled in by the user and then submitted as an HTTP PUT request. Your Rails app should have a model for the resource that is being updated, with a controller that has an 'update' action to accept the form parameters.

If you want to see the data that is being sent in the PUT request, you can use Firebug.

zetetic
+1  A: 

The form_for function will make its best guess in where to send the form:

Take the following code for instance:

<% form_for @user do |form| %>
  1. If @user is a new record, it will send a POST request to /users
  2. If @user is an existing record, it will send a PUT request to /users/12 (If 12 = @user.id)
Doug Neiner
A: 

You can see put method on edit when you run

rake routes


new_account  GET    /account/new(.:format)  {:action=>"new", :controller=>"accounts"}
edit_account GET    /account/edit(.:format) {:action=>"edit", :controller=>"accounts"}
account      GET    /account(.:format)      {:action=>"show", :controller=>"accounts"}
             PUT    /account(.:format)      {:action=>"update", :controller=>"accounts"} //this is your method needed
             DELETE /account(.:format)      {:action=>"destroy", :controller=>"accounts"}
             POST   /account(.:format)      {:action=>"create", :controller=>"accounts"}

<% form_for @user do |form| %> can be <% form_for :user, :url => user_url(:user), :method => :put do |form| %>

Kuya