Fields_for 多态:没有将 Symbol 隐式转换为 Integer

Fields_for Polymorphic: no implicit conversion of Symbol into Integer

我正在尝试创建一个 Group 和一个嵌套关联(Wathlist,多态)但是我得到了这个错误:

没有将符号隐式转换为整数

型号

class Group < ApplicationRecord
  belongs_to :user
  has_many :watchlists
  accepts_nested_attributes_for :watchlists, allow_destroy: true

end

class Watchlist < ApplicationRecord
  belongs_to :group
  belongs_to :watchable, polymorphic: true
end

控制器

def create
    @group = Group.new(group_params)  <---- ERROR HERE
    @group.user = current_user

  end


# Never trust parameters from the scary internet, only allow the white list through.
    def group_params
      params.require(:group).permit(:name,
        watchlists_attributes: [:watchable_type, :watchable_id]
      )
    end

查看

  <%=form_for(Group.new) do |f| %>
          <div class="form-group">
            <label for="listlabelname">Create new list</label>
            <%=f.text_field :name, class:"form-control", placeholder: "Enter a name"%>
              <%= f.fields_for :watchlists_attributes do |w| %>
                  <%=w.hidden_field :watchable_type, value: @watchable.class %>
                  <%=w.hidden_field :watchable_id, value: @watchable.id %>
              <% end %>

          </div>
          <%=f.submit "Create list", class:"btn btn-primary"%>
        <% end %>

已解决添加:监视列表,Watchlist.new

<%= f.fields_for :watchlists, Watchlist.new do |w| %>
   <%=w.hidden_field :watchable_type, value: @watchable.class %>
   <%=w.hidden_field :watchable_id, value: @watchable.id %>
<% end %>