public
Description:
Home | Edit | New

Field Overrides

If you want to customize the presentation of a column, you can define a specially named method in your helper file. The format is #{column_name}_column. So, for example, to customize the :username column displayed on your UsersController, you would add a username_column method to your UsersHelper file.

This override method accepts one argument: the entire record object. It is your responsibility to retrieve the interesting value from the record and to clean the value with h().

This override method is used by List and Show.

Example:

class User < ActiveRecord::Base
  has_many :roles
end

module UsersHelper
  # joins the first three roles with a hyphen instead of the normal comma.
  # ok, so this one isn't very original.
  def roles_column(record)
    unless record.roles.empty?
      record.roles.first(3).collect{|role| h(role)}.join(' - ')
    else
      # This way there's something to turn into a link if there are no roles associated with this record yet.
      active_scaffold_config.list.empty_field_text
    end
  end

  # creates a popup link to the associated division (belongs_to association)
  def division_column(record)
    link_to(h(record.division.name), :action => :show, :controller => 'divisions', :id => record.division.id)
  end
end
Last edited by scambra, Wed Sep 23 07:03:12 -0700 2009
Home | Edit | New
Versions: