2013-03-19 90 views
0

我有一個模型叫做遊戲。它有兩個協會:與:categorytoptens和:categorygames:多個has_many通過相同的關聯模型 - activeadmin形式

has_many :categorytoptens 
has_many :categories, :through => :categorytoptens, :dependent => :destroy 

has_many :categorygames 
has_many :categories, :through => :categorygames, :dependent => :destroy 

編輯的類別,我已將此添加到我的activeadmin games.rb文件:

f.input :categories, :as => :check_boxes, :collection => Category.all, :member_label => :navititle_de 

它顯示了所有的複選框列表類別模型中的類別並將選擇保存在類別遊戲中。所以,一切正常。

但是:當我改變的順序:categorytoptens和:在博弈模型categorygames,分類保存在categorytoptens:

has_many :categorygames 
has_many :categories, :through => :categorygames, :dependent => :destroy 

has_many :categorytoptens 
has_many :categories, :through => :categorytoptens, :dependent => :destroy 

我的問題:

a)是它「允許「具有多個具有相同模型關聯的has_many?模特協會是否「相互覆蓋」? 乙)有沒有辦法指定在activeadmin編輯模型?

非常感謝!

回答

1

那麼你不應該定義兩個has_many關聯同名!永遠不要嘗試重命名你的關聯

has_many :categorygames 
has_many :games_categories, :through => :categorygames, :dependent => :destroy 

has_many :categorytoptens 
has_many :top_ten_categories, :through => :categorytoptens, :dependent => :destroy 

答:你可以定義兩個關聯有相同的名稱,但後續覆蓋前一個。爲每個協會嘗試一些不錯的名稱(uniq)

B)需要更多信息,你想管理活動管理中的資源嗎?

嘗試

ActiveAdmin.register YourResourceName do 
end 

您可以設置自定義名稱爲您的資源過多,請點擊此鏈接http://activeadmin.info/docs/2-resource-customization.html#rename_the_resource

+0

非常感謝,就像一個魅力。最後我必須添加「:source =>」。 – flyte321 2013-03-19 16:54:21

相關問題