Rails Admin - Can not customize a new action instead of show in app action

I've followed this tutorial for creating a new rails admin action.

1.create a file name in_app_show.rb in lib folder:

 require 'rails_admin/config/actions'
    require 'rails_admin/config/actions/base'
    module RailsAdmin
      module Config
        module Actions
          class InAppShow < RailsAdmin::Config::Actions::Base
            RailsAdmin::Config::Actions.register(self)
            register_instance_option :member do
              true
            end
            register_instance_option :visible? do
              authorized? && (bindings[:controller].main_app.url_for(bindings[:object]) rescue false)
            end
            register_instance_option :controller do
              proc do
                redirect_to main_app.url_for(@object)
              end
            end
            register_instance_option :link_icon do
              'icon-camera-retro'
            end
            register_instance_option :pjax? do
              false
            end
          end
        end
      end
    end

2.In rails_admin.rb I did as you see :

require Rails.root.join('lib','in_app_show.rb')
    RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::InAppShow)
    RailsAdmin.config do |config|
     ....
    end
  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    # show_in_app
    in_app_show   
  end

But the icon and the action didn't turn up.As you can see here there is no file related to show_in_app.rb .I think in the latest version of rails admin there is no show in app action any longer! Could you please help me to have an action like that ? Thanks alot

1 answer

  • answered 2018-01-14 14:23 Daniel

    I built an app using your code. And I guess the problem is that you redirected your path. Here is my code: ``````

    require 'rails_admin/config/actions'
    require 'rails_admin/config/actions/base'
    module RailsAdmin
      module Config
        module Actions
          class InAppShow < RailsAdmin::Config::Actions::Base
            RailsAdmin::Config::Actions.register(self)
            register_instance_option :member do
              true
            end
            register_instance_option :visible? do
               authorized? && (bindings[:controller].main_app.url_for(bindings[:object]) rescue false)
            end
            register_instance_option :controller do
              proc do
                flash[:notice] = "Your customized action #{@action}"
                respond_to do |format|
                  format.html { render file: "#{Rails.root}/app/views/in_app_show"  }
                end
              end
            end
            register_instance_option :link_icon do
              'icon-camera-retro'
            end
            register_instance_option :pjax? do
              false
            end
          end
        end
      end
    end``````