What you want to do is whitelist every key in params[:checkout_item][:data]
, which is a hash. You can use the keys
method here to return an array of the keys for that hash.
params.require(:checkout_item).permit(:checkout_group_transaction_id,
:item_type, :property_id, :image,
{:data => params[:checkout_item][:data].try(:keys)})
Now every key in params[:checkout_item][:data]
will be permitted regardless of how many keys appear for a given request. Note the use of try
to avoid raising a NoMethodError
exception on params[:checkout_item][:data]
in the event that it is nil
since you may not need to pass the :data
sub hash on every request to create or update.
I took this idea from the action controller rails guide section 4.5.4 Outside the Scope of Strong Parameters.
Hope this helps!