Class: Admin::ListController

Inherits:
ApplicationController
  • Object
show all
Includes:
Callbacks
Defined in:
app/controllers/admin/list_controller.rb

Overview

Abstract controller providing a basic list action (#index). The action lists all entries of a certain model and provides functionality to search and sort this list. Furthermore, it remembers the last search and sort parameters after the user returns from a displayed or edited entry. The loaded model entries are available in the view as an instance variable named after the model_class or by the helper method entries.

Direct Known Subclasses

CrudController

Defined Under Namespace

Modules: Callbacks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#render_with_callbacks

Class Method Details

.model_classObject

The ActiveRecord class of the model.


84
85
86
# File 'app/controllers/admin/list_controller.rb', line 84

def model_class
  @model_class ||= controller_name.classify.constantize
end

.models_label(plural = true) ⇒ Object

A human readable plural name of the model.


89
90
91
92
93
94
95
# File 'app/controllers/admin/list_controller.rb', line 89

def models_label(plural = true)
  opts = { count: (plural ? 3 : 1) }
  opts[:default] = model_class.model_name.human.titleize
  opts[:default] = opts[:default].pluralize if plural

  model_class.model_name.human(opts)
end

Instance Method Details

#index(&block) ⇒ Object

List all entries of this model.

GET /entries
GET /entries.json

25
26
27
# File 'app/controllers/admin/list_controller.rb', line 25

def index(&block)
  respond_with(:admin, entries, &block)
end