Hi Hassan Schroeder,
thanks for replay it.
So, to solve the problem I had to create a unique ID to each element.
That was easy I used this code:
<% fields_for "invoice[items_attributes][#{Time.now.tv_usec.to_s}]",
invoice_item do |form_invoice_item| -%>
And with Time.now.tv_usec.to_s I created a unique ID for each group of
elements, and e got the params hash like this:
Parameters: {"commit"=>"Cadastrar", "invoice"=>{"mode"=>"in",
"items_attributes"=>{ "239625"=>[{"price"=>"2", "should_destroy"=>"",
"quantity"=>"2", "id"=>"109", "item"=>"2"}],
"48717"=>[{"price"=>"5", "quantity"=>"5",
"item"=>"5"}],
"238297"=>[{"price"=>"1", "should_destroy"=>"",
"quantity"=>"1", "id"=>"108", "item"=>"1"}],
"240939"=>[{"price"=>"4", "should_destroy"=>"",
"quantity"=>"4", "id"=>"110", "item"=>"4"}],
"236847"=>[{"price"=>"3", "should_destroy"=>"",
"quantity"=>"3", "id"=>"107", "item"=>"3"}]},
"total"=>"123", "id"=>"45", "company_id"=>"10"},
"authenticity_token"=>"560d84898abf599368ad8ef6972ffbb649ecf0ee"}
( http://pastie.org/340083 ).
But I got a problem when accessing those attributes in my model.
It was like this:
...
items_attributes.each do |attributes|
invoice_item.build(attributes)
...
and I have to add a [1] to access the right attributes.
...
items_attributes.each do |attributes|
invoice_item.build(attributes[1])
...
The attributes[0] give me = 239625, and
attributes[1] = price2should_destroyquantity2id109item2
To create I new record, every thing was ok.
To edit, I have to access the ID of the attributes variable... and I
don't know how. I have tried attributes[1][:id], attributes[1][0],
attributes[1][id].
Nothing seems to work. My model source code is here:
http://pastie.org/340088
So to sum up, how can I access the Id attributes of attributes[1]
Thanks
David Sousa
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---