Class RGhost::Grid::Rails
In: grid/rails_grid.rb
Parent: RGhost::Grid::Base

Grid::Rails differs from the other ones only in the mapping of the model attributes to be printed in the column. For example, the class Calls inherits ActiveRecord::Base.

Example

  rails_grid=Grid::Rails.new(:align => :center, :width => 3)

Mapping, first the attribute name then the already known optionsName

 rails_grid.column :mobile,   :title => "Mobile", :align => :right
 rails_grid.column :duration, :title => "Duration",:width => 3
 rails_grid.column :start,    :title => "Start", :format => :eurodate
 rails_grid.column :called,   :title => "Number", :align => :right, :title_align => :center

Loading data

  calls = Call.find(:all, :limit => 5000)
  rails_grid.data(calls)

Relationships

For relationships we use a block or a String instead of an attribute name (Symbol). Example

  class Accounts < ActiveRecord::Base
    belongs_to :customer
  end
  class Customers < ActiveRecord::Base
    has_many :accounts
  end

  c = Customers.find(:all, :include => :accounts )

Using a block

  g=Grid::Rails.new  :width => 4
  g.column :id,         :title => "Customer id"
  g.column :name,       :title => "Name",   :width => 6
  g.column :created_on, :title => "Date ",  :format => lambda{|d| d.strftime("%m/%d/%Y") }
  g.column lambda { accounts.first.login }, :title => "Login"
  g.column lambda { accounts.first.type },  :title => "Account Type"
  g.data(c)

Or a String

  g.column 'accounts.first.login', :title => Login"

Methods

data  

Public Instance methods

The parameter _data is ActiveRecord::Base Array.

[Validate]