Problem with deleting multiple users

Hello!

I’m a beginner with ruby on rails, so I don’t really know what I’m doing
:wink:

I have a index.html.erb where I list users. Before every user is a
checkbox, which I’d like to use when destroying several users.

I hope someone can help me :slight_smile:

index.html.erb:

<% form_tag destroy_marked_users_path, :method => :put do %> <% for user in @users %> <%# @users.each do |user| %> <% end %>
Name
<%= check_box_tag "user_ids[]", user.id %> <%=h user.name %> <%= link_to 'Show', user_links_path(user) %> <%= link_to 'Edit', edit_user_path(user) %> <%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %>

<%= submit_tag "Destroy_marked" %> <% end %>


In user_controller.rb I have:
def destroy_marked
@user.destroy_all(:id => params[:user_ids])
end


and routes.rb:
map.root :controller => “home”
map.resources :users, :has_many => :links, :collection => {
:destroy_marked => :put }

When I click Destroy_marked on index-page, I get error:‘Couldn’t find
User with ID=destroy_marked’

I guess there is something wrong with routes? I just can’t figure out
what, I don’t understand the routes :frowning:

Here is the development.log (it shouldn’t say ‘Processing
UsersController#update’???) :
Processing UsersController#index (for ::ffff:127.0.0.1 at 2009-04-16
13:10:35) [GET]
[4;35;1mUser Load (1.2ms) [0m [0mSELECT * FROM “users” [0m
Rendering template within layouts/users
Rendering users/index
[4;36;1mCACHE (0.0ms) [0m [0;1mSELECT * FROM “users” [0m
Completed in 46ms (View: 22, DB: 1) | 200 OK [http://localhost/users]

Processing UsersController#update (for ::ffff:127.0.0.1 at 2009-04-16
13:10:38) [PUT]
Parameters: {“commit”=>“Delete marked”,
“authenticity_token”=>“Ir9CWYijcM2LnHs1TShkUY6p4m4Czzl7+Cgyl+PEtVA=”,
“user_ids”=>[“8”, “9”], “id”=>“destroy_marked”}
[4;35;1mUser Load (0.2ms) [0m [0mSELECT * FROM “users” WHERE
(“users”.“id” = 0) [0m

ActiveRecord::RecordNotFound (Couldn’t find User with
ID=destroy_marked):
app/controllers/users_controller.rb:97:in find_user' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in each’
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in start’
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start’

Rendered rescues/_trace (102.7ms)
Rendered rescues/_request_and_response (0.5ms)
Rendering rescues/layout (not_found)


Here is also rake routes -result:
users GET /users(.:format) {:controller=>“users”, :action=>“index”}
POST /users(.:format) {:controller=>“users”, :action=>“create”}
new_user GET /users/new(.:format) {:controller=>“users”,
:action=>“new”}
edit_user GET /users/:id/edit(.:format) {:controller=>“users”,
:action=>“edit”}
user GET /users/:id(.:format) {:controller=>“users”,
:action=>“show”}
PUT /users/:id(.:format) {:controller=>“users”, :action=>“update”}
DELETE /users/:id(.:format) {:controller=>“users”, :action=>“destroy”}
root / {:action=>“index”, :controller=>“home”}
destroy_marked_users PUT /users/destroy_marked(.:format)
{:controller=>“users”, :action=>“destroy_marked”}
GET /users(.:format) {:controller=>“users”, :action=>“index”}
POST /users(.:format) {:controller=>“users”, :action=>“create”}
GET /users/new(.:format) {:controller=>“users”, :action=>“new”}
GET /users/:id/edit(.:format) {:controller=>“users”,
:action=>“edit”}
GET /users/:id(.:format) {:controller=>“users”, :action=>“show”}
PUT /users/:id(.:format) {:controller=>“users”, :action=>“update”}
DELETE /users/:id(.:format) {:controller=>“users”, :action=>“destroy”}
user_links GET /users/:user_id/links(.:format)
{:controller=>“links”, :action=>“index”}
POST /users/:user_id/links(.:format) {:controller=>“links”,
:action=>“create”}
new_user_link GET /users/:user_id/links/new(.:format)
{:controller=>“links”, :action=>“new”}
edit_user_link GET /users/:user_id/links/:id/edit(.:format)
{:controller=>“links”, :action=>“edit”}
user_link GET /users/:user_id/links/:id(.:format)
{:controller=>“links”, :action=>“show”}
PUT /users/:user_id/links/:id(.:format) {:controller=>“links”,
:action=>“update”}
DELETE /users/:user_id/links/:id(.:format) {:controller=>“links”,
:action=>“destroy”}