0

I want to mass assign array of objects in rails 4. How should I set strong parameters for this requirement?

My Controller assignment code

if a_params
  a_params.each do |param,index|
    a = A.new(param)
  end
end

My permit code

def a_params    
  params.permit(attr: [:a,:b,:c,:d,:e])
end

Doesn't work. My post json is as follows.

{
    "email" : "mail",
    "attr": [
        {
            "a" : "StarBucks",
            "b" : "2015-02-15T23:02:22+08:00",
            "c" : "12.3",
            "d" : "1",
            "e" : "http://www.google.com"
        },
        {
            "a" : "Macdonalds",
            "b" : "2015-02-15T23:02:22+08:00",
            "c" : "12.3",
            "d" : "1",
            "e" : "http://www.google.com"
        }
    ]
}
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
MadNik
  • 7,713
  • 2
  • 37
  • 39

1 Answers1

0

Found the issue. For anyone struggling with the same issue. It should be.

if a_params
  a_params['attr'].each do |param,index|
   a = A.new(param)
  end
end
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
MadNik
  • 7,713
  • 2
  • 37
  • 39