I am using the 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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.