Class: Admin::BaseController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/base_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.responderObject



8
9
10
# File 'app/controllers/admin/base_controller.rb', line 8

def responder
::Admin::Responder
end

Instance Method Details

#collection_nameObject Also known as: plural_name



36
37
38
# File 'app/controllers/admin/base_controller.rb', line 36

def collection_name
  resource_name.try(:pluralize)
end

#current_collectionObject



48
49
50
# File 'app/controllers/admin/base_controller.rb', line 48

def current_collection
  instance_variable_get("@#{collection_name}")
end

#current_resourceObject



44
45
46
# File 'app/controllers/admin/base_controller.rb', line 44

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

#current_resource_classObject



28
29
30
# File 'app/controllers/admin/base_controller.rb', line 28

def current_resource_class
  @current_resource_class ||= controller_name.singularize.camelize.constantize rescue nil
end

#fetch_current_resourceObject



57
58
59
60
# File 'app/controllers/admin/base_controller.rb', line 57

def fetch_current_resource
  return if !params[:id] || current_resource 
  instance_variable_set("@#{resource_name}", current_resource_class.find(params[:id]))
end

#resource_nameObject Also known as: singular_name



32
33
34
# File 'app/controllers/admin/base_controller.rb', line 32

def resource_name
  current_resource_class && current_resource_class.name.demodulize.underscore
end

#subjectObject



24
25
26
# File 'app/controllers/admin/base_controller.rb', line 24

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

#title_column(model) ⇒ Object



52
53
54
55
# File 'app/controllers/admin/base_controller.rb', line 52

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