[AWDR] Tutorial in A4 wont 'destroy' items

Hello,

I’m working through the tutorial, and I’ve run into a little snag. In
the first part of the tutorial, the destroy link is not working
correctly. I can’t figure out where I goofed. Removing :confirm doesn’t
seem to resolve the issue.

Thanks,
Randy.

development.log
----->8-----
Processing AdminController#destroy (for 127.0.0.1 at 2006-04-27
20:50:19) [GET]
Session ID: e578c5805fdb4b4abc61674cbb89e6c9
Parameters: {“action”=>“destroy”, “id”=>“2”, “controller”=>“admin”}
Redirected to http://localhost:3000/admin/list
Filter chain halted as
[#Proc:0x03314798@c:/devel/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/verification.rb:64]
returned false
Completed in 0.01600 (62 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/admin/destroy/2]
----->8-----

list.rhtml
----->8-----

<%= link_to ‘Show’, :action => ‘show’, :id => product %>

<%= link_to ‘Edit’, :action => ‘edit’, :id => product %>

<%= link_to ‘Destroy’, { :action => ‘destroy’, :id => product },
:confirm => “Are you sure?” %>

----->8-----

admin_controller.rb (unmodified)
----->8-----
def destroy
Product.find(params[:id]).destroy
redirect_to :action => ‘list’
end
----->8-----

Hmm, copying & pasting from the book didn’t change anything. Why will it
not allow me to delete items???

Hi Randy,

Have you tried examining the content of params[:id] in ‘Destroy’, just
to be
sure the find is working? I think params[:id].inspect will make it
print
out, but I’m still pretty new to RoR and my debugging skills aren’t
where
I’d like them to be yet :wink: I’m using Firebug on Firefox which shows
the
params hash for each request.

hth,
Bill
----- Original Message -----
From: “Randy W. Sims” [email protected]
To: [email protected]
Sent: Friday, April 28, 2006 2:40 PM
Subject: Re: [Rails] [AWDR] Tutorial in A4 wont ‘destroy’ items

Bill W. wrote:

Hi Randy,

Have you tried examining the content of params[:id] in ‘Destroy’, just
to be sure the find is working? I think params[:id].inspect will make
it print out, but I’m still pretty new to RoR and my debugging skills
aren’t where I’d like them to be yet :wink: I’m using Firebug on Firefox
which shows the params hash for each request.

Hi Bill,

Thanks for responding. I tried it again tonight on my Ubuntu linux
system at home with the same results. As soon as I modify the list.rhtml
file, I loose the ability to “destroy” items. That is the only change
necessary to cause the failure. It looks like AdminController#destroy is
not getting called.

I’m not familiar enough with Ruby or Rails to figure out what’s going
on.

Frustrated,
Randy.

Bill W. wrote:

show, and edit an item but then are not able to delete that same item?
If so, did you copy/paste your code in your original post? Or did you
retype some of it? Lots of folks have worked through that tutorial, so
it’s probably something small. Hang in there!

Yeah, I have tried the code you posted with no results which is why I
thought it wasn’t getting called. Show & Edit work properly, only
Destroy fails. They all get called with the same id. Destry works up to
the point where I make the change to list.rhtml. It fails even when I
copy & paste the code directly from the pdf.

Thanks,
Randy.

Hi Randy,

Randy W. Sims wrote:

It looks like AdminController#destroy is not getting called.

The first line in your error log below shows that
AdminController#destroy is
in fact getting called. That’s why I suggested you check the params
value.
Can you verify that you can add, show, and edit an item but then are not
able to delete that same item? If so, did you copy/paste your code in
your
original post? Or did you retype some of it? Lots of folks have worked
through that tutorial, so it’s probably something small. Hang in there!

Best regards,
Bill

Just ran into this problem too. In case your probem is still open, this
is
what solved it for me:

changed :confirm => ‘Are you sure?’ to :confirm => ‘Are you sure?’,
*
:post* => true in the view. Scaffold generated controllers by default do
not
accept database modifications with a get method.

Hope this helps,

Marcel.

I believe that this is a change that came out in Rails 1.1.

In Rails 1.0 and before, the controllers generated by script generate
scaffold would accept destroy requests that came in via gets.

In Rails 1.1, the following code was added to the output from generate
scaffold:

GETs should be safe (see

URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }

I suspect this is causing the behavior you are seeing.


Steven Chanin

From: Dormanns M. [email protected]
Reply-To: [email protected]
Date: Fri, 5 May 2006 21:17:50 +0200
To: [email protected], [email protected]
Subject: Re: [Rails] [AWDR] Tutorial in A4 wont ‘destroy’ items

Just ran into this problem too. In case your probem is still open, this
is
what solved it for me:

changed :confirm => ‘Are you sure?’ to :confirm => ‘Are you sure?’ ,
:post
=> true in the view. Scaffold generated controllers by default do not
accept
database modifications with a get method.

Hope this helps,

Marcel.

Randy W. Sims wrote:

AdminController#destroy is in fact getting called. That’s why I
the point where I make the change to list.rhtml. It fails even when I
copy & paste the code directly from the pdf.

It’s an error in the book. I created another depot app without
modifications. It worked, so I diffed it, and found

  • <%= link_to 'Destroy', {:action => 'destroy', :id => product},
  •                            :confirm => "Are you sure?" %></td>
    
    • <%= link_to 'Destroy', { :action => 'destroy', :id => product

      }, :confirm => ‘Are you sure?’, :post => true %>

      Adding :post => true, solved the problem.

      Randy.

Re: [Rails] [AWDR] Tutorial in A4 wont ‘destroy’ itemsThanks for the
explanation, Steven. Excellent information.

Best regards,
Bill
----- Original Message -----
From: Steven Chanin
To: [email protected]
Sent: Saturday, May 06, 2006 9:36 AM
Subject: Re: [Rails] [AWDR] Tutorial in A4 wont ‘destroy’ items

I believe that this is a change that came out in Rails 1.1.

In Rails 1.0 and before, the controllers generated by script generate
scaffold would accept destroy requests that came in via gets.

In Rails 1.1, the following code was added to the output from generate
scaffold:

# GETs should be safe (see 

URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }

I suspect this is causing the behavior you are seeing.


Steven Chanin


From: Dormanns M. [email protected]
Reply-To: [email protected]
Date: Fri, 5 May 2006 21:17:50 +0200
To: [email protected], [email protected]
Subject: Re: [Rails] [AWDR] Tutorial in A4 wont ‘destroy’ items

Just ran into this problem too. In case your probem is still open,
this is what solved it for me:

changed :confirm => ‘Are you sure?’ to :confirm => ‘Are you sure?’ ,
:post => true in the view. Scaffold generated controllers by default do
not accept database modifications with a get method.

Hope this helps,

Marcel.

On 4/30/06, Randy W. Sims [email protected] wrote:

Bill W. wrote:
> Hi Randy,
>
> Randy W. Sims wrote:
>
>> It looks like AdminController#destroy is not getting called.
>>
>
> The first line in your error log below shows that
> AdminController#destroy is in fact getting called.  That's why I
> suggested you check the params value. Can you verify that you can 

add,
> show, and edit an item but then are not able to delete that same
item?
> If so, did you copy/paste your code in your original post? Or did
you
> retype some of it? Lots of folks have worked through that
tutorial, so
> it’s probably something small. Hang in there!

Yeah, I have tried the code you posted with no results which is why 

I
thought it wasn’t getting called. Show & Edit work properly, only
Destroy fails. They all get called with the same id. Destry works up
to
the point where I make the change to list.rhtml. It fails even when
I
copy & paste the code directly from the pdf.

Thanks,
Randy.
_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails



Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails