Custom model in rails_admin

旧城冷巷雨未停 提交于 2019-12-24 11:29:43

问题


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.


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/12424293/custom-model-in-rails-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!