[英]Using rails_admin to display dropdown list on belongs_to association
I am using rails_admin
to manage data in a rails application. 我使用
rails_admin
来管理rails应用程序中的数据。
I have this class: 我有这门课:
class Activity < ActiveRecord::Base
attr_accessible :content, :title, :category_id
belongs_to :category, :inverse_of => :activities
end
And the other end is: 另一端是:
class Category < ActiveRecord::Base
attr_accessible :title, :category_id, :activities_ids
has_many :activities, :inverse_of => :category
end
My rails_admin initialiser for Activity looks like this: 我的Activity的rails_admin初始化程序如下所示:
config.model Activity do
edit do
field :title
field :content, :text do
bootstrap_wysihtml5 true
end
field :category
end
end
Now, in the form it renders the category like this: 现在,在表单中呈现如下类别:
It is supposed to render the names of categories, right? 它应该呈现类别的名称,对吗? What am I missing here?
我在这里错过了什么?
I've been looking for this for quite a while. 我一直在寻找这个问题。 To get a really nice autocomplete dropdown just add:
要获得一个非常好的自动完成下拉列表,只需添加:
config.model Activity do
edit do
field :category, :belongs_to_association
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.