ruby - Rails strong parameters with objects array -


when using rails 4.0 strong parameters, how permit json this?

{    "user":    {        "first_name":"jello"    },    "users_to_employer":[        {            "start_date":"2013-09-03t16:45:27+02:00",            "end_date":"2013-09-10t16:45:27+02:00",            "employer":{"company_name":"telenor"}        },        {            "start_date":"2013-09-17t16:45:27+02:00",            "end_date":null,            "employer":{"company_name":"erixon"}        }    ] } 

i tried following:

 params.require(:users_to_employers => []).permit(                                                  :start_date,                                                   :end_date => nil,                                                  :employer => [                                                      :company_name                                                  ]) 

but didn't work.

try

params.permit(users_to_employers: [{ :start_date, :end_date, employer: [ :company_name ]]) 

this should work


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -