Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
README.rdoc
index_view.gemspec

README.rdoc

IndexView

IndexViews are objects that that are composed of models and also have methods to define how those models are presented in the view. They're ideal to use in admin sections of your application and make it lightning fast to handle:

* pagination
* column sorting
* searchability
* reusability and reusability

IMAGE TO AN INDEXVIEW IN THE WILD

Examples:

Defining an IndexView

class UsersIndex < IndexView::Base
  column :email,
         :sortable => true
  column :time_zone
  column :type,
         :sortable => true

  def target_class
    User
  end

  def default_sort_term
    :id
  end

  def default_sort_direction
    :ASC
  end
end

Using an IndexView in an action

class Admin::UsersController < Admin::ApplicationController

  def index
    @index = UsersIndex.new(params)
    @users = @index.paginate
  end

end

When your index shows data from more than one model(For example: A User and all his comments) we find it helpful to either denormalize that information or make an ActiveRecord model backed by a view, not a a plain-old table - and use that class as your target_class.

Overriding a value

Need to give something other than then the column value / method for a column? Pass in a block and you'll get the record back:

class UserIndex < IndexView::Base

column :name do |user|
  "#{user.first_name} #{user.last_name}"
end

end

Something went wrong with that request. Please try again.