views:

618

answers:

4

<% form_ tag user_path(@user), :method => :put do %>

That's my form, so I want it to access the update method of my UsersController, I set the map.resources :users , and the RESTful paths generated:

users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create",:controller=>"users"}

new_ user GET /users/new(.:format) {:action=>"new", :controller=>"users"}

edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}

user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}

PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}

DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}

So I try to send to user_path(@user) using the PUT HTTP method and it comes back with:

Unknown action

No action responded to 1. Actions: create, destroy, edit, index, logged?, new, show and update

So obviously I don't know how to make this work, so thanks in advance.

+1  A: 

Just a shot in the dark, but have you tried this?

<% form_tag :url=>user_path(@user), :html=>{:method=>:put} do %>
Scott
+3  A: 

If you're using RESTful resources (and you should be), try using form_for not form_tag ... with the full setup like this:

<% form_for :user, @user, :url=>user_path(@user), :html=>{:method=>:put} do |f| %>

  #this scopes the form elements to the @user object, eg.
  <%= f.text_field :first_name %>

<% end %>

Check out the API docs for more.

mylescarrick
A: 

Did you restart your server? My routes.rb never gets reloaded correctly if I update it while the server is running.

Wahnfrieden
A: 

I ran into this exact problem when trying to use a tableless model (http://stackoverflow.com/questions/315850/rails-model-without-database).

After some quick digging into actionpack's form_helper.rb I found a solution. Add this to your model:

def new_record?; false; end

In my case my model is always built from scratch so this was necessary to "trick" Rails into treating it as an existing object, and thus doing a PUT rather than a POST.

alalonde