2012-03-27 29 views
1

我想通過表單將一組玩家分配到一個固定裝置。HABTM表單不提交超過一個值的軌道

我一直試圖從我的玩家列表中選中所有玩家,通過複選框讓用戶可以選擇他想要的夾具。

模式 有3種型號的燈具concedered和球員

class Fixture < ActiveRecord::Base 
belongs_to :team 
has_many :player_fixtures 
has_many :players, :through => :player_fixtures 
has_one :venue 

class Player < ActiveRecord::Base 
has_and_belongs_to_many :teams 
has_many :player_fixtures 
has_many :fixtures, :through => :player_fixtures 

class PlayerFixture < ActiveRecord::Base 
belongs_to :player 
belongs_to :fixture 

我需要使用:through與球員和夾具的關聯。無論這個人是否付錢,我都需要一個布爾值。

這些工作的關聯,我可以通過控制檯將連接表中的玩家分配到連接表中。

查看 在我看來,我有:

<%= form_for(:fixture, :url => {:action =>'create'}) do |f| %> 

這是我一直在試圖讓目前工作的代碼!

<%= f.collection_select(:player, :player_id, @players,:id, :name, { :include_blank => true ,:multiple => true}) %> 

編輯

我現在已經插入下面的評論,也改變了集合選擇:

<%= f.collection_select(:player_ids, Player.all,:id, :name, {:include_blank => true ,:multiple => true}) %> 

目前我得到的上嘗試加載表格下面的錯誤:

undefined method `merge' for :name:Symbol 

就這一行

28:  <td><%= f.collection_select(:fixture, :player_id, Player.all,:id, :name, { :include_blank => true ,:multiple => true}) %> 

這可能是可怕的錯誤,但我真的需要得到這個工作,因爲這是我的項目的很大一部分。

任何人都可以指向正確的方向嗎?如果有人想沿着形式化的路線發送,那麼隨意,因爲我也無法得到那份工作。

回答

0

你應該通過目標對的form_for而不是符號:

<%=form_for(:fixture, :url => {:action =>'create'}) do |f| %> 

應該

<%= form_for(@fixture, :url => {:action =>'create'}) do |f| %> 

更新:

看起來像你沒有定義的has_many:player_fixtures在夾具模型,has_many:通過首先要求它。

class Fixture < ActiveRecord::Base 
belongs_to :team 
has_many :player_fixtures 
has_many :players, :through => :player_fixtures 
has_one :venue 
+0

我已經做了這個,但我仍然有一些錯誤! *請參閱編輯* – JPKnegte 2012-03-28 16:10:35

+0

查看更新回答 – 2012-03-29 02:29:30

+0

完成此操作但仍然有另一個錯誤煩人!謝謝你的幫助 – JPKnegte 2012-03-29 15:09:07