Module: InheritedViews::TableBuilder::ClassMethods

Defined in:
lib/inherited_views/table_builder.rb

Instance Method Summary collapse

Instance Method Details

#default_table_columnsObject



21
22
23
# File 'lib/inherited_views/table_builder.rb', line 21

def default_table_columns
  resource_class.content_columns.collect{|column| column.name.to_sym  }
end

#table(*columns) ⇒ Object

Sets the columns to be displayed when the index table is rendered for this resource.

Simple usage:

Pass in a list of the methods to call on your resource in the order you wish to see them in the table

class UsersController < InheritedViews::Base

table :first_name, :last_name

end

Except:

You can also use the default content columns from your ActiveRecord object and only exclude certain columns.

class UsersController < InheritedViews::Base

table :except => :first_name

end



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/inherited_views/table_builder.rb', line 48

def table(*columns)
  options = columns.extract_options!        
  
  if options[:except]
    options[:except] = options[:except].is_a?(Array) ? options[:except] : [options[:except]]
    columns = default_table_columns
    options[:except].each{|c| columns.delete(c) }
  end
  
  self.table_config = options.merge(:columns => columns)
end