ruby on rails - How to fix mass-assign protected attributes issue? -
i keep getting error saying can't mass-assign protected attributes: product_id when run code in controller below. i've confirmed @product exist. advice on how fix this?
controller:
@product = product.find(1) = category.new(:category => 'glasses', :product_id => @product.id) a.save class product < activerecord::base attr_accessible :blog has_many :categories end class category < activerecord::base attr_accessible :category belongs_to :product end
writing
@product = product.find(1) @product.categories.create(:category => 'glasses') is more elegant , should solve problem.
Comments
Post a Comment