Reading Hash/Array

Hi all,

My app is generating a form with several bill_items that should be
updated (fields to be updated are description and net).

The text_field_tag names are bill_item[update][#{id}][description] and
bill_item[update][#{id}][net] (and I added bill_item[update][#{id}]
[id] just in case)

The param received is:



How can I read/process this data?

I am trying to do something like

params[:bill_item][:update].each do |item|
  bill_item = BillItem.find(item[id])
  bill_item.description = item[description] = item[net]

but of course the access to the hash is not correct.

I know that item[id] is not correct, thats why I said that the access
to the hash is incorrect (I should have been more specific), it was
just to give you and idea of what I wanted.

If I try to item["id"] rails tells me "can't convert String into

And if I try to use item["id"].to_i, the error reported remains the

def update_data
    unless params[:bill_item].nil? || params[:bill_item][:update].nil?
      params[:bill_item][:update].each do |item|
        bill_item = BillItem.find(item["id"].to_i)
        bill_item.description = item["description"] = item["net"]
      end[:notice] = 'Item(s) updated'
    else[:warning] = 'No data received'

can't convert String into Integer

app/controllers/billing_controller.rb:101:in `[]'
app/controllers/billing_controller.rb:101:in `update_data'
app/controllers/billing_controller.rb:100:in `each'
app/controllers/billing_controller.rb:100:in `update_data'
app/controllers/billing_controller.rb:63:in `update_items'
base.rb:1168:in `send'

       "description"=>"Daily monitoring",

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.

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,

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] = value[:net]

Again, thanks for your help Ryan!