Destroy action doesn't work?

Hi all,

Here is my Customer controller’s destroy method:

** def destroy
redirect_to :action => ‘list’

It’s stock, untouched scaffold code. When I submit the URL:


The entry in the MySQL database with id 11 is not destroyed. The
method won’t destroy any MySQL entries. Any idea why this is?

  • David

Tail your development.log to see what SQL is being issued after you
submit. That will enable you to debug.

        - dan

Dan K. mailto:[email protected] tel:+1-415-233-1000

Is there any output in the development log?

Thanks for the tip to look into the development log, guys. How handy
little file is; I fixed my problem. I’ll describe it here so future
newbies can benefit.

When I looked into the development.log file (located in /railsroot/log/)
found this little bit:

Processing CustomersController#destroy (for IPADDRESS at 2006-07-14
06:29:52) [GET]
Session ID: 90bcac762fc4f986fcb499be95271082
Parameters: {“action”=>“destroy”, “id”=>“11”,
Redirected to http://localhost:3000/customers/list
Filter chain halted as
returned false
Completed in 0.00045 (2222 reqs/sec) | DB: 0.00000 (0%) | 302 Found [

The point to notice is the part that says, “Filter chain halted as
returned false.” This is important because it’s telling me that the
verification (verification.rb) isn’t being submitted as true.
we’re not confirming the destruction of the SQL entry.

My “Destroy” link looked like this:

<%= link_to ‘Destroy’, :action => ‘destroy’, :id => @customer %>

When I checked this against the correct scaffold code, I found that the
should be:

<%= link_to ‘Destroy’, { :action => ‘destroy’, :id => @customer },
=> ‘Are you sure?’, :post => true %>

This way, the application will ask, “Are you sure?” and require a “Yes”
“OK” from the user before it will destroy the SQL entry. Because I
including the confirmation bit in the code, the required Yes or OK
have a chance to be submitted with the request, so Rails wasn’t
the entry.

Thanks again!

  • David

On Monday, July 24, 2006, at 12:35 PM, David R. wrote:

Parameters: {“action”=>“destroy”, “id”=>“11”, “controller”=>“customers”}
should be:
Thanks again!

Hi all,

Rails mailing list
[email protected]

Actually the important bit is the ‘:post=>true’.

The confirmation is simply a JS alert but otherwise does nothing.
The scaffold is set up to require a ‘post’ method for calls to
destructive actions, the before_filter that requires the ‘post’ is what
stopped the action from running.