Update_attributes

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 %>

Hi –

On Thu, 5 Oct 2006, magic_hat wrote:

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 | [email protected]
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

I almost bought the book the other day – it looked really good. Now
I’ll definitely have to :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs