Generic-user-small Mark Adkins 2 posts

I’ve copied the delete_user action directly from the book. It’s exactly the same. However, instead of deleting a user, I get this error:

ActiveRecord::RecordNotFound in LoginController#delete_user

Couldn't find User with ID=user

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1031:in `find_one'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1014:in `find_from_ids'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:419:in `find'
#{RAILS_ROOT}/app/controllers/login_controller.rb:46:in `delete_user'
 
Generic-user-small Mark Adkins 2 posts

Ack, sorry. Didn’t mean to hit submit.

This is the code for delete_user:

def delete_user if request.post? user = User.find(params[:id]) begin user.destroy flash[:notice] = "User #{user.name} deleted." rescue Exception => e flash[:notice] = e.message end end redirect_to(:action => :list_users) end

The problem line, apparently, is 46: user = User.find(params[:id])

But, I don’t know why it’s wrong. Any thoughts?

2 posts, 1 voice