Sha256: 526f06a3228bc53ead6804264d7e4ebfee6030c9714858109e69196cb8cd4b1a

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 KB

Contents

class Admin::BaseController < ApplicationController
  before_filter :authenticate_administrator!
  before_filter :fetch_current_resource
  
  layout 'admin'
    
  class << self
    def responder
    ::Admin::Responder
    end
  end
  
  helper_method :singular_name,
                :plural_name,
                :resource_name,
                :collection_name,
                :current_resource_class,
                :current_resource, 
                :current_collection,
                :title_column,
                :subject


  def subject
    @subject ||= ::Admin::SubjectModelAdapter.new(current_administrator)
  end

  def current_resource_class
    @current_resource_class ||= controller_name.singularize.camelize.constantize rescue nil
  end
  
  def resource_name
    current_resource_class && current_resource_class.name.demodulize.underscore
  end
  
  def collection_name
    resource_name.try(:pluralize)
  end

  alias :singular_name :resource_name
  alias :plural_name :collection_name
  

  def current_resource
    instance_variable_get("@#{resource_name}")
  end

  def current_collection
    instance_variable_get("@#{collection_name}")
  end
  
  def title_column(model)
    @_title_columns ||= {}
    @_title_columns[model] ||= ( model.column_names.map{ |c| c.to_s } & %W(title name label browser_title seo_title seo_name key claim email kind) ).first
  end
  
  def fetch_current_resource
    return if !params[:id] || current_resource 
    instance_variable_set("@#{resource_name}", current_resource_class.find(params[:id]))
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fullstack-admin-0.2.26 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.25 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.24 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.23 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.22 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.21 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.20 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.19 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.18 app/controllers/admin/base_controller.rb