I\'m new to Rails and built something based on this
http://railscasts.com/episodes/403-dynamic-forms
but I have a problem with storing data in the additional
If you want to return a nested hash as a parameter you have to name the keys in the array in permit.
class ProductsController < ApplicationController
def new
@product = Product.new(product_type_id: params[:product_type_id])
end
def product_params
params.require(:product).permit(:name, :price, :product_type_id, {:properties => [:foo, :bar, :id]})
end
If you are generating the keys dynamically and can't code them into the permit statement then you need to use this style:
def product_params
params.require(:product).permit(:name, :price, :product_type_id).tap do |whitelisted|
whitelisted[:properties] = params[:product][:properties]
end
end
It's not the most friendly code for a new user, I just finished the 3 course rails certificate at UW and they never even covered .tap.
This is not my work, I'm still just understanding the deeper parts of .permit like this. This is the blog entry I used: Strong Parameters by Example