簡體   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