Insert multiple form values

Hi,

How do I parse these parameters to insert into a table:

Parameters: {“commit”=>“Add Contacts to List”,
“contact_list”=>{“contact_id”=>[“4”, “5”], “list_id”=>“3”}}

Two records should be created.

One where:

list_id = 3
contact_id = 4

And another where:

list_id = 3
contact_id = 5

Thanks,

David

Just do:

params[:contact_ids].each { |cid| YourModel.create(…) }

Cheers
Starr

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs