Reputation: 1173
I have a rails 4 app where I have a Product Model that has columns: Title (string), Description (text), and Data (text, but I'm storing JSON inside).
What I'm trying to do is similar to what the nested_form gem (by Ryan Bates) provides. I've been searching but can't seem to find a way to have multiple fields, say I want to store inside the data column a json object of color:blue and size:big.
I have inside my _form:
<input type='text name="product[data][]">
but I'm getting the error:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WHzAChBlWH6bOSUzUp50sSTt1hm/6/Uruuy7TY4LY8I=", "product"=>{"title"=>"fdsaf", "data"=>["fsdsadfsdf", "fasdfsdf"]}, "commit"=>"Create Product"}
Unpermitted parameters: data
Basically my question is how can I using rails generate a text field for color and size (but could be anything) that then save as JSON? Similar to how the nested_form gem allows you to have a "Add Field"?
Upvotes: 0
Views: 42
Reputation: 2015
You might not added the data field in strong parameters, This might work and wont give the above error.
params.require(:product).permit(:name, data: [])
Upvotes: 1