Re: A basic collections/hash question

comopasta Gr
Wed, 09 Sep 2009 12:42:29 -0000

Hi Mukund, thanks for the suggestions!

I did try

> params[:subscribers].each do |subscriber_hash|
     puts subscriber_hash
>    my_record = Subscriber.new(subscriber_hash)
>    my_record.save
> end if params[:subscribers]

The result is that subscriber_hash results in

subscriber
nameSixmsidsm555imsi555imei555
nameSevenmsidsm444imsi444imei444

Ok so far I guess. But then Subscriber.new(subscriber_hash) fails as
seen below:

Processing SubscribersController#import (for 127.0.0.1 at 2009-09-09
15:36:05) [POST]
  Parameters: {"action"=>"import",
"subscribers"=>{"subscriber"=>[{"name"=>"Six",
"msidsm"=>"555",
"imsi"=>"555", "imei"=>"555"},
{"name"=>"Seven", "msidsm"=>"444",
"imsi"=>"444", "imei"=>"444"}]},
"controller"=>"subscribers"}
...
...
NoMethodError (undefined method `stringify_keys!'' for
#<Array:0xb6041008>):
  app/controllers/subscribers_controller.rb:49:in `new''
  app/controllers/subscribers_controller.rb:49:in `import''
  app/controllers/subscribers_controller.rb:47:in `each''
  app/controllers/subscribers_controller.rb:47:in `import''
  /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service''
  /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run''
  /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread''
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start''
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread''
  /usr/lib/ruby/1.8/webrick/server.rb:95:in `start''
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `each''
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `start''
  /usr/lib/ruby/1.8/webrick/server.rb:23:in `start''
  /usr/lib/ruby/1.8/webrick/server.rb:82:in `start''

Cheers.