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 => :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)


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

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

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

Using a block  :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"

Or a String

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



Public Instance methods

The parameter _data is ActiveRecord::Base Array.