Custom model in rails_admin

2019-08-02 23:00发布

I have such problem:

I'm using rails_admin and gem acts_as_taggable_on. Second have model ActsAsTaggableOn::Tag. And I need to manage it in admin part. Google and StackOverflow don't know answer, or I forgot, how to google =(

So, what I tried: Added that in initializers/rails_admin.rb

config.model ActsAsTaggableOn::Tag do
  label 'Тэг'
  label_plural 'Тэги'
  configure :name, :string
end

Still no reaction. But if I try to add config.included_models = [ActsAsTaggableOn::Tag] Then I see that model in admin, but this is whitelist, so I see there only tags, no other model =)

Tried to

config.included_models = :all

and

config.included_models << ActsAsTaggableOn::Tag

Still nothing =(

I would be very grateful if anybody can help me.

P.S. Nowtime see only one way - add empty class ActsAsTaggableOn::Tag in app/models But I think, that is not good way.

2条回答
疯言疯语
2楼-- · 2019-08-02 23:36

The following will give you the ability to list, filter, edit, search tags and see how many times they are used. This example does not give one the ability to change the item using a tag or its association to said tag.

Create the file: app/models/tag.rb

Define the contents as:

class Tag < ActsAsTaggableOn::Tag
  attr_accessible :name, :as => :admin
end
查看更多
SAY GOODBYE
3楼-- · 2019-08-02 23:49

You need to add them all if you go Whitelist mode:

config.included_models = ['ActsAsTaggableOn::Tag', <all other models>]

You can run rake rails_admin:installto have the list of all the models that RailsAdmin has detected in config/initializers/rails_admin.rb.example

查看更多
登录 后发表回答