I have got a Products class,Products are visible to zero or many roles . so i have created a polymorphic model called content_roles,which stores the id of the role and content_id (which will be product_id,or event_id),and content_type(product,event etc).
I am using nested_form gem for accepting the role id(using check_box) to store the product and role relation in content_role
the Issue I am facing is I am not able to create a content_role record . in my logs i get unpermitted parameters : role_id
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxxxxxxxxxxxxxxxxxxxdLH99ZWLrf8dgT3gcBops=", "product"=>{"product_name"=>"some product", "product_description"=>"some product description", "content_roles_attributes"=>{"role_id"=>["1", "2", ""]}}, "commit"=>"Create Product"}
in my view I have written
= f.simple_fields_for :content_roles_attributes do |role|
= role.input :role_id,label: "visible to", as: :check_boxes,label: "Role",collection: Role.all,:required=>true
the controllers permitted params looks like
def product_params
params.require(:product).permit(:product_description,:product_name,
content_roles_attributes: [:role_id,:id],
multimedia_attributes:[:asset,:_destroy,:id])
end
the product model looks like
class Product
has_many :content_roles, as: :content
has_many :multimedia ,as: :storable
# Nested attributes
accepts_nested_attributes_for :multimedia
accepts_nested_attributes_for :content_roles
end
and this is the content_role model
class ContentRole < ActiveRecord::Base
belongs_to :content, polymorphic: true
belongs_to :role
belongs_to :news
belongs_to :product
end