[英]Rails admin and has_and_belongs_to_many
I am using the Rails Admin gem. 我正在使用Rails Admin gem。 And I have the following two models: 我有以下两种型号:
class Category < ActiveRecord::Base
attr_accessible :description, :name
has_and_belongs_to_many :experiences
end
class Experience < ActiveRecord::Base
attr_accessible :description, :city_id, :price, :title, :user_id
attr_accessible :categories
validates :title, :description, :user_id, :presence => true
belongs_to :user
belongs_to :city
has_and_belongs_to_many :categories
end
In the Rails admin, I am not able to add a category to an existing Experience. 在Rails管理员中,我无法将类别添加到现有体验中。 In the edit site of a particular Experience, I see this: 在特定体验的编辑网站中,我看到:
As you can see I can't select any categories, even though I have several categories created. 正如您所看到的,即使我创建了多个类别,也无法选择任何类别。
It was solved by adding the following into the Experience model: 通过在体验模型中添加以下内容解决了这个问题:
attr_accessible :category_ids
instead of 代替
attr_accessible :categories
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.