繁体   English   中英

Rails管理员和has_and_belongs_to_many

[英]Rails admin and has_and_belongs_to_many

我正在使用Rails Admin gem。 我有以下两种型号:

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

在Rails管理员中,我无法将类别添加到现有体验中。 在特定体验的编辑网站中,我看到:

经验不能添加类别

正如您所看到的,即使我创建了多个类别,也无法选择任何类别。

通过在体验模型中添加以下内容解决了这个问题:

attr_accessible :category_ids

代替

attr_accessible :categories

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM