Skip to content
scambra edited this page Sep 14, 2010 · 14 revisions

In show views columns are rendered with the same format as in list views. If you want to customize the presentation of a column in the show view, you can define a specially named method in your helper file. The format is #{column_name}_show_column. So, for example, to customize the :username column displayed on your show view of UsersController, you would add a :username_show_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 Show.

Example:


class User < ActiveRecord::Base
  has_many :roles
end

module UsersHelper

  1. joins the first three roles with a hyphen instead of the normal comma.
  2. ok, so this one isn’t very original.
    def roles_show_column(record)
    record.roles.first(3).collect{|role| h(role)}.join(’ – ’)
    end
  1. creates a popup link to the associated division (belongs_to association)
    def division_show_column(record)
    link_to(h(record.division.name), :action => :show, :controller => ‘divisions’, :id => record.division.id)
    end
    end
Clone this wiki locally