我正在尝试通过创建商店表单将标签添加到商店。 为此,我使用了嵌套属性,但是出现以下错误:
没有将符号隐式转换为整数
提取的来源(第492行附近):
association.target
else
attribute_ids = attributes_collection.map { |a| a["id"] || a[:id] }.compact
attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids)
end
我的代码是:
Shop.rb
class Shop < ApplicationRecord
has_many :shop_tags , dependent: :destroy
has_many :tags, through: :shop_tags
accepts_nested_attributes_for :tags
end
shops_controller.rb
def create
@shop = Shop.new(shop_params)
# scaffold code
end
def shop_params
params.require(:shop).permit(
:longitude, :latitude, :name, :description, :state, :address,
tags_attributes:[:name, :id])
end
_form.html.erb
<%= form_with(model: @shop , local: true, scope: "shop") do |form| %>
#the first part of the form
<div class="form-group">
<%= form.fields_for :tags_attributes do |form| %>
<%= form.label :name, %>
<%= form.text_field :name ,class:'form-control' %>
<% end %>
</div>
<% end %>
我尝试将:tags_attributes
或:tags
的field_for :tag
更改,但出现了不允许的参数错误。
谢谢!