Skip to content

Commit

Permalink
Refactored #determine_active_admin_layout into the BaseController
Browse files Browse the repository at this point in the history
  • Loading branch information
gregbell committed Jan 15, 2013
1 parent 04e038c commit ce09276
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
16 changes: 15 additions & 1 deletion lib/active_admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ActiveAdmin
class BaseController < ::InheritedResources::Base
helper ::ActiveAdmin::ViewHelpers

layout 'active_admin'
layout :determine_active_admin_layout

before_filter :only_render_implemented_actions
before_filter :authenticate_active_admin_user
Expand Down Expand Up @@ -57,5 +57,19 @@ def active_admin_namespace
end
helper_method :active_admin_namespace


ACTIVE_ADMIN_ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy]

# Determine which layout to use.
#
# 1. If we're rendering a standard Active Admin action, we want layout(false)
# because these actions are subclasses of the Base page (which implements
# all the required layout code)
# 2. If we're rendering a custom action, we'll use the active_admin layout so
# that users can render any template inside Active Admin.
def determine_active_admin_layout
ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin'
end

end
end
14 changes: 0 additions & 14 deletions lib/active_admin/page_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class PageController < BaseController
# Active admin actions don't require layout. All custom actions do.
ACTIVE_ADMIN_ACTIONS = [:index]

layout :determine_active_admin_layout

actions :index

def index(options={}, &block)
Expand All @@ -18,17 +16,5 @@ def clear_page_actions!
active_admin_config.clear_page_actions!
end

private

# Determine which layout to use.
#
# 1. If we're rendering a standard Active Admin action, we want layout(false)
# because these actions are subclasses of the Base page (which implements
# all the required layout code)
# 2. If we're rendering a custom action, we'll use the active_admin layout so
# that users can render any template inside Active Admin.
def determine_active_admin_layout
ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin'
end
end
end
13 changes: 0 additions & 13 deletions lib/active_admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class ResourceController < BaseController
respond_to :html, :xml, :json
respond_to :csv, :only => :index

ACTIVE_ADMIN_ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy]

include Actions
include ActionBuilder
include Callbacks
Expand Down Expand Up @@ -50,17 +48,6 @@ def inherited(base)

private

# Determine which layout to use.
#
# 1. If we're rendering a standard Active Admin action, we want layout(false)
# because these actions are subclasses of the Base page (which implementes
# all the required layout code)
# 2. If we're rendering a custom action, we'll use the active_admin layout so
# that users can render any template inside Active Admin.
def determine_active_admin_layout
ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin'
end

# Returns the renderer class to use for the given action.
def renderer_for(action)
active_admin_namespace.view_factory["#{action}_page"]
Expand Down

0 comments on commit ce09276

Please sign in to comment.