Where do controller methods for rails_admin custom actions go?
-
12-12-2019 - |
Question
I created a custom action in RailsAdmin using https://github.com/sferik/rails_admin/wiki/Custom-action, but I'm unsure where I would put my controller methods within the custom action and if I use a form what would be the path to call those controller methods?
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow