I have one table named User.
In that i have two type of record :
1) Corporation
2) Agency
Field name is is_agency?(Boolean). If is agency then true and if is corporation then false.
I want to display User table to two different table Corporation and Agency in admin side. I used rails_admin gem.
How can i differentiate using "is_agency?" field ?
I check rails_admin gem documentation but i did't find any thing about this.
Please help me to find out this solution, it will save my hours.
答案 0 :(得分:0)
您可以按照此处所述创建自定义操作:https://github.com/sferik/rails_admin/wiki/Custom-action
例如
# in lib/rails_admin/agency.rb
require 'rails_admin/config/actions'
require 'rails_admin/config/actions/base'
module RailsAdmin
module Config
module Actions
class Agency < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :controller do
Proc.new do
@objects = Project.where(is_agency: true)
render "index"
end
end
register_instance_option :collection do
true
end
register_instance_option :link_icon do
'icon-th-list'
end
end
end
end
end
然后你必须将它添加到rails_admin.rb初始化程序
config.actions do
dashboard # mandatory
index
agency do
only ['User']
end
然后为公司做同样的事情。
不要忘记将翻译添加到locales rails_admin.en.yml
另一种方法是使用范围: https://github.com/sferik/rails_admin/wiki/List 在文本中搜索范围。
希望这有帮助, 最好的祝福, 扬