I''m a noob having a hard time, and it''s probably really simple. Here''s the way it''s set up: Client has many Bins Bin belongs to Client In my Client show view I have it render a partial that lists all the records in Bin associated with Client. I need to have a destroy link for each of the Bin records. Right now I have it configured in my Bin partial as: <%= link_to("Delete", { :action => "destroy", :id => @bin }, :confirm => "Are you sure?", :method => :delete) %> This just throws back an error saying that there is not a Client with that id. I can''t figure out how to tell it to delete the bin not the client with that id. Any helpful suggestions? Cheers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-20 22:39 UTC
Re: How to delete a record inside of an association
On 20 Mar., 20:57, Nate <CrossRoadStud...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m a noob having a hard time, and it''s probably really simple. > > Here''s the way it''s set up: > Client has many Bins > Bin belongs to Client > In my Client show view I have it render a partial that lists all the > records in Bin associated with Client. > > I need to have a destroy link for each of the Bin records. Right now I > have it configured in my Bin partial as: > <%= link_to("Delete", { :action => "destroy", :id => @bin }, :confirm > => "Are you sure?", :method => :delete) %> > > This just throws back an error saying that there is not a Client with > that id. > > I can''t figure out how to tell it to delete the bin not the client > with that id. > > Any helpful suggestions? Cheers.I guess it''s because, that when you''re rendering partials you''ll not be given an instance variable, but a local variable. You can try to see if this is enough to fix the problem: <%= link_to("Delete", { :action => "destroy", :id => bin.id }, :confirm => "Are you sure?", :method => :delete) %> I simply removed the @ to reference a local variable instead. (And I call the #id method on the Bin, but that''s optional.) -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Mar-20 23:11 UTC
Re: How to delete a record inside of an association
On Mar 20, 10:39 pm, "ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org" <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> wrote:> On 20 Mar., 20:57, Nate <CrossRoadStud...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m a noob having a hard time, and it''s probably really simple. > > > Here''s the way it''s set up: > > Client has many Bins > > Bin belongs to Client > > In my Client show view I have it render a partial that lists all the > > records in Bin associated with Client. > > > I need to have a destroy link for each of the Bin records. Right now I > > have it configured in my Bin partial as: > > <%= link_to("Delete", { :action => "destroy", :id => @bin }, :confirm > > => "Are you sure?", :method => :delete) %> > > > This just throws back an error saying that there is not a Client with > > that id. > > > I can''t figure out how to tell it to delete the bin not the client > > with that id. > > > Any helpful suggestions? Cheers. > > I guess it''s because, that when you''re rendering partials you''ll not > be given an instance variable, but a local variable. You can try to > see if this is enough to fix the problem: >No. The problem is the current controller is the client controller, so :action => destroy routes you to /clients/destroy, which unsurprisingly destroys clients not bins. If you''re feeling old school you would add :controller => ''bins'' to your hash, but a more modern way to do this would be link_to ''Delete'', bin_path(@bin), :method => :delete Fred> <%= link_to("Delete", { :action => "destroy", :id => > bin.id }, :confirm > => "Are you sure?", :method => :delete) %> > > I simply removed the @ to reference a local variable instead. (And I > call the #id method on the Bin, but that''s optional.) > > -- > Cheers, > David Knorrhttp://twitter.com/rubyguy--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---