[英]Add actions using Rails admin gem
Suppose I want to add two actions(active and pause) with the show edit delete and show_in_app actions. 假设我想通过show edit delete和show_in_app操作添加两个操作(活动和暂停)。 So how can i accomplish this?
那我该怎么做呢? I went through https://github.com/sferik/rails_admin/wiki/Actions but i am not able to get the right way..
我经历了https://github.com/sferik/rails_admin/wiki/Actions,但我无法找到正确的方法。
this is my rails_admin.rb 这是我的rails_admin.rb
RailsAdmin.config do |config|
config.actions do
dashboard # mandatory
index # mandatory
new
export
bulk_delete
show
edit
delete
show_in_app
end
end
ANY HELP????? 任何帮助吗???
Custom actions are powerful but a bit tricky. 自定义操作功能强大,但有些棘手。 Here is what I did:
这是我所做的:
rails_admin.rb rails_admin.rb
require Rails.root.join('lib', 'rails_admin', 'custom_actions.rb')
custom_actions.rb custom_actions.rb
module RailsAdmin
module Config
module Actions
class Foo
RailsAdmin::Config::Actions.register(self)
register_instance_option :visible? do
# which model
end
register_instance_option :member do
true
end
register_instance_option :link_icon do
'fa fa-star'
end
register_instance_option :controller do
Proc.new do
# put your code here
flash[:notice] = "your message here"
redirect_to show_path
end
end
end
en.yml 英文
en:
admin:
actions:
foo:
menu: 'foo menu'
title: 'foo title'
breadcrumb: 'foo breadcrumb'
I wrote a blog post on it http://dmitrypol.github.io/2015/09/10/rails_admin.html 我在上面写了一篇博客文章http://dmitrypol.github.io/2015/09/10/rails_admin.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.