Forum: Ruby on Rails Problem with deleting multiple users

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Marika A. (Guest)
on 2009-04-16 17:45

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

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 :)


    <% form_tag destroy_marked_users_path, :method => :put do %>
      <% for user in @users %>
      <%# @users.each do |user| %>
  <td><%= check_box_tag "user_ids[]", %>

  <td><%=h %></td>
  <td><%= link_to 'Show', user_links_path(user) %></td>
  <td><%= link_to 'Edit', edit_user_path(user) %></td>
  <td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method
=> :delete %></td>
    <% end %>
   <%= submit_tag "Destroy_marked" %>
   <% end %>

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

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 :(

Here is the development.log (it shouldn't say 'Processing
UsersController#update'????) :
Processing UsersController#index (for ::ffff: 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: at 2009-04-16
13:10:38) [PUT]
  Parameters: {"commit"=>"Delete marked",
"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
  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",
edit_user GET    /users/:id/edit(.:format) {:controller=>"users",
user GET    /users/:id(.:format)  {:controller=>"users",
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",
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",
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",
DELETE /users/:user_id/links/:id(.:format)      {:controller=>"links",
This topic is locked and can not be replied to.