Fixed it.
I used item[0], item[1] and item[2] to access the array. But when I
did this, I noticed that the description (= item[1]) was receiving: !
map:HashWithIndifferentAccess (...) so actualy item[1] was returning a
hash instead of the description. Then I understood how rails was
(correctly) interpreting the whole params[:bill_item].
[:update] was an array, with the key being the id of the field, and
the value being the hash with the params that I sent (id, description,
net)
So this is the correct/working code:
params[:bill_item][:update].each do |key, value|
bill_item = BillItem.find(key.to_i)
bill_item.description = value[:description]
bill_item.net = value[:net]
bill_item.save
end
Again, thanks for your help Ryan!
On Dec 9, 7:38 pm, "Ryan Bigg" <
radarliste...@gmail.com> wrote:
> item is an array? I thought it would be a hash.
>
> Try doing a puts item.inspect in your code
>
> On Dec 10, 2007 1:52 PM,
felip...@gmail.com <
felip...@gmail.com> wrote:
>
>
>
>
>
> > Yes, 101 is the find.
>
> > If I try to use item = item.to_hash inside the do block, I get:
>
> > undefined method `to_hash' for #<Array:0x364a0e8>
>
> > This tells me that it is an array. But why the hell I'm not being able
> > to access its values? not even with item[1], item[2] etc.
>
> > How can I add something like debug(item) to the log so that I can see
> > it's structure?
>
> > Thanks for all the help Ryan.
>
> > On Dec 9, 7:20 pm, "Ryan Bigg" <
radarliste...@gmail.com> wrote:
> > > Not a clue. I'm guessing 101 is the item["id"].to_i line? That should be
> > > working.
>
> --
> Ryan Bigghttp://
www.frozenplague.net