Ruby on rails Rails 4个集合复选框,带有一个已通过的多个复选框
我正在尝试将类别与产品关联起来。 到目前为止,我实现它的方式是Ruby on rails Rails 4个集合复选框,带有一个已通过的多个复选框,ruby-on-rails,has-many-through,checkboxlist,categorization,Ruby On Rails,Has Many Through,Checkboxlist,Categorization,我正在尝试将类别与产品关联起来。 到目前为止,我实现它的方式是 Class Product has_many :categorizations has_many :categories, through: :categorizations 在我的产品中/_form.html.erb 我不知道该怎么做 解决方案 将::category\u id更改为:category\u id,并设置强参数 def产品参数 参数require(:product).permit(:ti
Class Product
has_many :categorizations
has_many :categories, through: :categorizations
在我的产品中/_form.html.erb
我不知道该怎么做
解决方案将:
:category\u id
更改为:category\u id
,并设置强参数
def产品参数
参数require(:product).permit(:title,:description,:price,:category_id=>[])
结束
因为关系是多对多的,所以给定的产品应该响应类别id
(复数),而不是类别id
(单数)。谢谢,这很有效。我还必须设置def product\u params.require(:product).permit(:title,:description,:image\u url,:price,:category\u id=>[])end
Class Categorization
belongs_to :product
belongs_to :category
Class Category
has_many :categorizations
has_many :products, through: :categorizations