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----- <td class="ListActions"> <%= link_to ''Show'', :action => ''show'', :id => product %><br /> <%= link_to ''Edit'', :action => ''edit'', :id => product %><br /> <%= link_to ''Destroy'', { :action => ''destroy'', :id => product }, :confirm => "Are you sure?" %> </td> ----->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??? Randy W. Sims wrote:> 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----- > <td class="ListActions"> > <%= link_to ''Show'', :action => ''show'', :id => product %><br /> > <%= link_to ''Edit'', :action => ''edit'', :id => product %><br /> > <%= link_to ''Destroy'', { :action => ''destroy'', :id => product }, > :confirm => "Are you sure?" %> > </td> > ----->8----- > > admin_controller.rb (unmodified) > ----->8----- > def destroy > Product.find(params[:id]).destroy > redirect_to :action => ''list'' > end > ----->8-----
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 ;-) I''m using Firebug on Firefox which shows the params hash for each request. hth, Bill ----- Original Message ----- From: "Randy W. Sims" <ml-ruby@thepierianspring.org> To: <rails@lists.rubyonrails.org> Sent: Friday, April 28, 2006 2:40 PM Subject: Re: [Rails] [AWDR] Tutorial in A4 wont ''destroy'' items> Hmm, copying & pasting from the book didn''t change anything. Why will it > not allow me to delete items??? > > Randy W. Sims wrote: >> 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----- >> <td class="ListActions"> >> <%= link_to ''Show'', :action => ''show'', :id => product %><br /> >> <%= link_to ''Edit'', :action => ''edit'', :id => product %><br /> >> <%= link_to ''Destroy'', { :action => ''destroy'', :id => product }, >> :confirm => "Are you sure?" %> >> </td> >> ----->8----- >> >> admin_controller.rb (unmodified) >> ----->8----- >> def destroy >> Product.find(params[:id]).destroy >> redirect_to :action => ''list'' >> end >> ----->8----- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Bill Walton 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 ;-) 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.> ----- Original Message ----- From: "Randy W. Sims" > <ml-ruby@thepierianspring.org> > To: <rails@lists.rubyonrails.org> > Sent: Friday, April 28, 2006 2:40 PM > Subject: Re: [Rails] [AWDR] Tutorial in A4 wont ''destroy'' items > > >> Hmm, copying & pasting from the book didn''t change anything. Why will >> it not allow me to delete items??? >> >> Randy W. Sims wrote: >> >>> 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----- >>> <td class="ListActions"> >>> <%= link_to ''Show'', :action => ''show'', :id => product %><br /> >>> <%= link_to ''Edit'', :action => ''edit'', :id => product %><br /> >>> <%= link_to ''Destroy'', { :action => ''destroy'', :id => product }, >>> :confirm => "Are you sure?" %> >>> </td> >>> ----->8----- >>> >>> admin_controller.rb (unmodified) >>> ----->8----- >>> def destroy >>> Product.find(params[:id]).destroy >>> redirect_to :action => ''list'' >>> end >>> ----->8----- >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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
Bill Walton 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.
Randy W. Sims
2006-Apr-30 15:28 UTC
[Rails] [AWDR] Tutorial in A4 wont ''destroy'' items <= *Book Errata*
Randy W. Sims wrote:> Bill Walton 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.It''s an error in the book. I created another depot app without modifications. It worked, so I diffed it, and found - <td><%= link_to ''Destroy'', {:action => ''destroy'', :id => product}, - :confirm => "Are you sure?" %></td> + <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => product }, :confirm => ''Are you sure?'', :post => true %></td> Adding :post => true, solved the problem. Randy.
Dormanns Marcel
2006-May-05 19:17 UTC
[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 <ml-ruby@thepierianspring.org> wrote:> > Bill Walton 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 > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/736f493a/attachment.html
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 http://www.w3.org/2001/tag/doc/whenToUseGet.html) 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 Marcel <dormanns@gmail.com> Reply-To: <rails@lists.rubyonrails.org> Date: Fri, 5 May 2006 21:17:50 +0200 To: <RandyS@thepierianspring.org>, <rails@lists.rubyonrails.org> 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 <ml-ruby@thepierianspring.org> wrote:> Bill Walton 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 > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060506/57a16c67/attachment.html
Re: [Rails] [AWDR] Tutorial in A4 wont ''destroy'' itemsThanks for the explanation, Steven. Excellent information. Best regards, Bill ----- Original Message ----- From: Steven Chanin To: rails@lists.rubyonrails.org 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 http://www.w3.org/2001/tag/doc/whenToUseGet.html) 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 Marcel <dormanns@gmail.com> Reply-To: <rails@lists.rubyonrails.org> Date: Fri, 5 May 2006 21:17:50 +0200 To: <RandyS@thepierianspring.org>, <rails@lists.rubyonrails.org> 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 <ml-ruby@thepierianspring.org> wrote: Bill Walton 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 Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails ------------------------------------------------------------------------------ _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails ------------------------------------------------------------------------------ _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060506/d37d18bf/attachment.html