lib/active_admin/base_controller.rb in activeadmin-0.5.1 vs lib/active_admin/base_controller.rb in activeadmin-0.6.0
- old
+ new
@@ -1,15 +1,17 @@
require 'inherited_resources'
+
+require 'active_admin/base_controller/authorization'
require 'active_admin/base_controller/menu'
module ActiveAdmin
# BaseController for ActiveAdmin.
# It implements ActiveAdmin controllers core features.
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
class << self
@@ -27,10 +29,11 @@
def only_render_implemented_actions
raise AbstractController::ActionNotFound unless action_methods.include?(params[:action])
end
include Menu
+ include Authorization
private
# Calls the authentication method as defined in ActiveAdmin.authentication_method
def authenticate_active_admin_user
@@ -54,8 +57,22 @@
def active_admin_namespace
active_admin_config.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