ruby - Accepting polymorphic associations through checkbox in rails -



ruby - Accepting polymorphic associations through checkbox in rails -

i have got products class,products visible 0 or many roles. so, have created polymorphic model called content_roles,which stores id of role , content_id (which product_id,or event_id),and content_type(product,event etc).

i using nested_form gem accepting role id(using check_box) store product , role relation in content_role

i error no implicit conversion of string integer in products#create function

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 view have written

= f.simple_fields_for :content_roles_attributes |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 create #getting error @ line @product = product.new(product_params) respond_to |format| if @product.save end def product_params params.require(:product).permit(:product_description,:product_name, content_roles_attributes: [:id,role_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 content_role model

class contentrole < activerecord::base belongs_to :content, polymorphic: true belongs_to :role belongs_to :news belongs_to :product end

ruby-on-rails ruby nested-forms polymorphic-associations

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -