2013-03-19 94 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