Sha256: 89382636cc088e3e1a87346d6e0e0e859f0a4f82a743220fdb6b0f835e995bf9

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

# Abstract controller providing a basic list action.
# The loaded model entries are available in the view as an instance variable
# named after the +model_class+ or by the helper method +entries+.
#
# The +index+ 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.
class ListController < ApplicationController

  include DryCrud::GenericModel
  prepend DryCrud::Nestable
  include DryCrud::RenderCallbacks
  include DryCrud::Rememberable

  define_render_callbacks :index

  helper_method :entries

  ##############  ACTIONS  ############################################

  #   GET /entries
  #   GET /entries.json
  #
  # List all entries of this model.
  def index
    entries
  end

  private

  # Helper method to access the entries to be displayed in the current index
  # page in an uniform way.
  def entries
    model_ivar_get(true) || model_ivar_set(list_entries)
  end

  # The base relation used to filter the entries.
  # Calls the #list scope if it is defined on the model class.
  #
  # This method may be adapted as long it returns an
  # <tt>ActiveRecord::Relation</tt>.
  # Some of the modules included extend this method.
  def list_entries
    model_class.respond_to?(:list) ? model_scope.list : model_scope
  end

  # Include these modules after the #list_entries method is defined.
  include DryCrud::Searchable
  include DryCrud::Sortable

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry_crud-6.0.0 app/controllers/list_controller.rb
dry_crud-5.2.0 app/controllers/list_controller.rb