Sha256: 81c134fc03c23b9965b492afa195aec8445c562e3e9aa9573e969286978c4289

Contents?: true

Size: 1.53 KB

Versions: 14

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) ).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

14 entries across 14 versions & 1 rubygems

Version Path
fullstack-admin-0.2.17 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.16 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.15 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.14 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.13 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.12 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.11 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.9 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.8 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.7 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.6 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.5 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.4 app/controllers/admin/base_controller.rb
fullstack-admin-0.2.3 app/controllers/admin/base_controller.rb