Rails 5:collection_select不保存

时间:2017-06-27 02:19:47

标签: html ruby-on-rails ruby web erb

我的表单有集合选择但不保存到数据库 表单尝试将玩家ID分配给"伪装者"记录

https://i.stack.imgur.com/vam9k.jpg

数据库模型:

 create_table "players", force: :cascade do |t|
    t.string "name"
    t.string "group"
    t.text "info"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "pretenders", force: :cascade do |t|
    t.string "name"
    t.string "archtype"
    t.string "magic"
    t.string "scale"
    t.integer "player_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

表格部分:

 <div class="field">
        <%= form.label :player_id %>
        <%= form.collection_select(:player_id, Player.all, :id, :name, {}, {:multiple => true, :size => '10'}) %>
      </div>

生成的html选择选项有值但不保存?

&#13;
&#13;
    <select multiple="multiple" size="10" name="pretender[player_id][]">
    <option value="1">sy</option>
    <option value="2">malakal</option>
    <option value="3">pigs go moo</option>
    <option value="4">malgrib</option>
    <option value="5">Rael</option>
    <option value="6">Nargo</option>
    <option value="7">salva</option>
    <option value="8">pbiecub</option>
    <option value="9">Jude</option>
    <option value="10">Cirno</option>
</select>
&#13;
&#13;
&#13;

这里是伪装者控制器的参数:

def pretender_params
  params.require(:pretender).permit(:name, :archtype, :magic, :scale, :player_id)
  params.require(:pretender).permit(:id)
end

尝试解决方案: Collection_select not saving &安培;其他页面,但网站赢了不让我发布更多链接lol

0 个答案:

没有答案