I''m working on a form that updates a product record and several associated detail records. The detail records are showing and populating okay in the form. But when it hits the controller, I get Couldn''t find Detail with ID=detail AND (details.product_id = 38). The :detail params seem to refer to the correct record id. Anyone have an idea how to fix this? Here''s the controller: def edit if request.get? @product = Product.find(params[:id], :order=>''gender, size'', :include=>''details'' ) else @product = product.find(params[:id]) [:detail].each {|id, attributes| @product.details.find(id).update_attributes(attributes)} if @product.update_attributes(params[:product]) flash[:notice] = ''product was successfully updated.'' redirect_to :action => ''show'', :id => @product else render :action => ''edit'' end end end And part of the view: <% for @detail in @product.details %> <%=text_field "detail[]", "remaining", :size=>4 %> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Oct-05 10:04 UTC
Re: update_attributes
Hi -- On Thu, 5 Oct 2006, magic_hat wrote:> > I''m working on a form that updates a product record and several > associated detail records. > > The detail records are showing and populating okay in the form. But > when it hits the controller, I get Couldn''t find Detail with ID=detail > AND (details.product_id = 38). The :detail params seem to refer to the > correct record id. Anyone have an idea how to fix this? > > Here''s the controller: > > def edit > if request.get? > @product = Product.find(params[:id], :order=>''gender, size'', > :include=>''details'' ) > else > @product = product.find(params[:id]) > [:detail].each {|id, attributes|You presumably want params[:detail] there, not just [:detail]. David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I almost bought the book the other day -- it looked really good. Now I''ll definitely have to :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---