A basic collections/hash question

comopasta Gr
Wed, 09 Sep 2009 09:23:11 -0000

Hi,

I give up trying. I need to ask this basic question about collections
and hashes.

I''m trying to do a batch update of records using XML:

<?xml version="1.0" encoding="UTF-8"?>
<subscribers>
<subscriber>
  <imei>111</imei>
  <imsi>111</imsi>
  <msidsm>111</msidsm>
  <name>Six</name>
</subscriber>
<subscriber>
  <imei>777</imei>
  <imsi>777</imsi>
  <msidsm>777</msidsm>
  <name>Seven</name>
</subscriber>
</subscribers>

I have this in the routes:

map.resources :subscribers, :collection => {:import => :post}

When I post the XML I get:

Processing SubscribersController#import (for 127.0.0.1 at 2009-09-09
12:18:22) [POST]
  Parameters: {"action"=>"import",
"subscribers"=>{"subscriber"=>[{"name"=>"Six",
"msidsm"=>"111",
"imsi"=>"111", "imei"=>"111"},
{"name"=>"Seven", "msidsm"=>"777",
"imsi"=>"777", "imei"=>"777"}]},
"controller"=>"subscribers"}

--------------------------------

How can I easily create subscriber records for those I send in the XML?
I''ve managed to extract the data but it fails when only one subscriber
element is included in the XML.

What would be the best way to do this?

Thanks.