我使用https://github.com/sferik/rails_admin/wiki/Custom-action在RailsAdmin中创建了一个自定义动作,但是我不确定我将控制器方法放在该自定义动作中的位置,如果我使用表单,那会怎样?是调用那些控制器方法的路径?
Here's an example of a custom action I'm using for pdf (project here ):
require "rails_admin_pdf/engine"
module RailsAdminPdf
end
require 'rails_admin/config/actions'
module RailsAdmin
module Config
module Actions
class Pdf < Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :member do
true
end
register_instance_option :controller do
Proc.new do
report = "#{@object.class.to_s.demodulize}Report".constantize.new
send_data report.to_pdf(@object), :filename => "#{@object.class.to_s.demodulize}_#{@object.id}.pdf", :type => "application/pdf"
end
end
end
end
end
end
So, to answer your question, the controller method goes inside the lib/rails_admin_*custom_action_name*.rb module. I'm not sure I understand the second part of your question regarding form submission. You can check out another example of a custom action with form submission here .
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.