1

I need to embed my active admin pages in a parent application. The active admin page will be shown in an iframe and I need to remove the header and footer on the default index, show and edit pages if the url query param embedded=true.

I proceed like this in my active admin page :

ActiveAdmin.register Followup, as: 'Followup_affectation' do

   controller do
     def setLayout
        if  params['embedded'] == 'true'
          @layout = false
        else
          @layout = 'active_admin'
        end
      end
end

And in some custom action

         render template: "admin/followups/mytemplate.html.haml", layout: @layout

But I want to do it for index.

I tried

def index
    render :index, layout: @layout
end

and

def index
   super
   render :index, layout: @layout
end

My index definition is really classic :

 index do
      id_column
      column :step
      column :cycle
      column :tag_rfid
      column :quoteline
      column :product_name
      column :location
      column :active
      actions
  end

Thanks in advance for your help

Jaycreation
  • 2,029
  • 1
  • 15
  • 30
  • 1
    could you do something like `before_action :setLayout, only: [:index, :show, :edit]` – Richlewis Jun 09 '17 at 14:34
  • @Richlewis thanks for your help but the issue is on How i remove the layout from the rendering. Scope the function does not help in this case – Jaycreation Jun 09 '17 at 14:52

1 Answers1

3

I finally find a solution. 1 - Create header.rb in app/admin/

module ActiveAdmin
  module Views
    class Header < Component

      def build(namespace, menu)
        super(id: "header")

        #add a class hide wich diplay none on the menu
        if params['embedded'] == 'true'
          super(class: "hide")
        end
        @namespace = namespace
        @menu = menu
        @utility_menu = @namespace.fetch_menu(:utility_navigation)

        build_site_title
        build_global_navigation
        build_utility_navigation
      end


      def build_site_title
        insert_tag view_factory.site_title, @namespace
      end

      def build_global_navigation
        #do not insert tag if params embedded is true
        insert_tag view_factory.global_navigation, @menu, class: 'header-item tabs' unless params['embedded'] == 'true'
      end

      def build_utility_navigation
        insert_tag view_factory.utility_navigation, @utility_menu, id: "utility_nav", class: 'header-item tabs'
      end

    end
  end
end
Jaycreation
  • 2,029
  • 1
  • 15
  • 30