为什么我使用HABTM Association获取未经许可的参数?

问题描述 投票:3回答:1

我目前正在开始构建一个开源的商店目录应用程序。

我有qazxsw poi和qazxsw poi模型通过qazxsw poi模型与FunShop assosiation连接。在FunSubcategory形式中,我以这种方式添加了FunSubcategorization复选框。

has_many :through

当我提交表单时出现错误FunShop

我对强参数了解一点,我怀疑它存在问题。在我的Subcategory控制器中我有这个:

<div class="field">
    <%= hidden_field_tag "fun_shop[fun_subcategory_ids][]", nil %>
    <% FunSubcategory.all.each do |category| %>
      <%= check_box_tag "fun_shop[fun_subcategory_ids][]", category.id, @fun_shop.fun_subcategory_ids.include?(category.id), id: dom_id(category) %>
      <%= label_tag dom_id(category), category.title %>
    <% end %>
</div>

我也在我的FunShop模型中做到了这一点:

Unpermitted parameters: fun_subcategory_ids

FunShop有一个相关的存储库。

ruby ruby-on-rails-4
1个回答
13
投票

解决了。

我需要添加这个:

def fun_shop_params
  params.require(:fun_shop).permit(:fun_subcategory_ids)
end  #Most code ommited for simplicity

指定它是一个数组。

© www.soinside.com 2019 - 2024. All rights reserved.