I need to save this array:
params[:products]
The array contains these information:
[{"'name'"=>"Product Name 1 ", "'id'"=>"2", "'quantity'"=>"2", "'accessory'"=>{"'id'"=>"8", "'name'"=>"Accessory Name 1"}}, {"'name'"=>"Product Name 2 ", "'id'"=>"5", "'quantity'"=>"1", "'accessory'"=>{"'id'"=>"40", "'name'"=>"Accessory Name 2"}}]
As you can see, accessory is another array.
The process is this: A front-end guy is givin me that array, So I want to store all data on order.rb model.
So, I have a couple of questions:
- Do I need to have "array type field" on database?.
- Which fields do I need?
I was looking for some examples and I've been trying this on my order model:
serialize :product
order = Order.new
order.product = [:product]
order.save
order.product
I red about this method too: http://api.rubyonrails.org/classes/ActiveRecord/Store.html
Maybe this is a basic question but I really don't know how to solve it. As you can see, I don't have code in any controller because I really don't know what I need to write.
Thank you for your help.
store :products, coder: JSON