i have product
model has many categories
, category
has many attributes
.
class product < activerecord::base has_many :categories, :dependent => :destroy accepts_nested_attributes_for :categories, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true attr_accessible :categories_attributes, :comments, :name, :price, :available, :image, :remote_image_url end class category < activerecord::base belongs_to :product has_many :attributes, :dependent => :destroy attr_accessible :name, :attributes_attributes accepts_nested_attributes_for :attributes, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true end class attribute < activerecord::base belongs_to :category attr_accessible :name, :value, :is_key end
my problem that, when try updating product
model, following error:
undefined method `keys' []:activerecord::relation
i have no keys
attribute in model, have is_key
in attribute
model, thinking problem comes from.
i using following form product
update:
.form_container = nested_form_for @product, :html => {:class => 'form'} |f| - if @product.errors.any? #error_explanation %h2= "#{pluralize(@product.errors.count, "error")} prohibited product being saved:" %ul - @product.errors.full_messages.each |msg| %li= msg .title product fields .field = f.label :name = f.text_field :name, :class => :required .field = f.label :price = f.text_field :price, :class => :required .field = f.label :comments = f.text_area :comments .field = f.label :product_type = select_tag 'product_type', options_from_collection_for_select(@product_types, 'id', 'name'), { :class => '' } %br/ .title image .field = f.file_field :image, :class => :file .field = f.label :remote_image_url, 'or image url' = f.text_field :remote_image_url %br/ .title specifications .field = f.fields_for :categories |category| = render 'category_fields', :f => category .field = f.link_to_add "add category", :categories, :class => 'button_link' .field = f.label :available = f.check_box :available, {checked: true} .actions = f.submit submit_button_name, :class => :submit
change line
has_many :attributes, :dependent => :destroy
to
has_many :category_attributes, :dependent => :destroy, :class_name => 'attribute'
along rest attr_accessible
etc. avoid conflict build in attributes rails method
Comments
Post a Comment