A basic collections/hash question

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

Assuming that SubscriberModel is an activerecord model that maps to a
table with similar layout as the hash.

Otherwise, define your own class with an initializer method like so
and do whatever you want with it.

class SubscriberModel
  attr_accessor :name, :msidsm, :imsi, :imei
  def initialize(init_hash={})
    @name = init_hash["name"]
    @msidsm = init_hash["msidsm"]
    @imsi = init_hash["imsi"]
    @imei = init_hash["imei"]
  end
end

Hi,

I managed to get over this problem.

The code I'm using now is:

data = params[:subcribers][:subscriber]
(data.is_a?(Array) ? data : [data]).each do |d|
   my_record = Report.create(d)
end

This works fine wether I have only one subscriber or many in the XML
Next will be doing a batch update. But that should be a different story
since my problem was doing the iteration with the data.

I found the hints from here:
http://railsforum.com/viewtopic.php?id=10888

Regards.