简体   繁体   中英

Using rails_admin to display dropdown list on belongs_to association

I am using rails_admin to manage data in a rails application.

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:

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

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.

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