railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.9k stars 2.26k forks source link

How to register Custom Section for Custom Action? #2895

Open yadwinderpaul opened 7 years ago

yadwinderpaul commented 7 years ago

Tried to add model specific custom action

# app/lib/rails_admin/config/actions/custom_action.rb

module RailsAdmin
  module Config
    module Actions
      class CustomAction < RailsAdmin::Config::Actions::Base

        RailsAdmin::Config::Actions.register(self)

        register_instance_option :member do
          true
        end

        register_instance_option :http_methods do
          [:get]
        end

        register_instance_option :controller do
          proc do
            puts "Do Foo"
          end
        end

        register_instance_option :link_icon do
          "fa fa-plus"
        end

      end
    end
  end
end
# app/lib/rails_admin/config/sections/custom_action.rb
require 'rails_admin/config/sections/base'

module RailsAdmin
  module Config
    module Sections
      class CustomAction < RailsAdmin::Config::Sections::Base

        register_instance_option :custom_option do
          :foo
        end

      end
    end
  end
end

But the app raises

undefined method `custom_action' for #<RailsAdmin::Config::Sections::Base:0x007fc61b32ac60>

when I try to do

# app/models/my_model.rb

class MyModel < ApplicationRecord

  rails_admin do
    custom_action do
      custom_option do
        :bar
      end
    end
  end

end

How do I register the custom_section with rails_admin? Already checked out #2574, #2066, #1844, but no help there.

ektaverma1 commented 7 years ago

Hi @yadwinderpaul ,

Did you get any solution for the above issue? I am also facing similar issue, wherein I am trying to create forms for my custom rails_admin actions and form submit should redirect to some specific action.

Please let me know if you have found out the way to achieve the same.

Thanks in advance.