API: Column

calculate

Defines a calculation on the column. Anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do. Only works on real columns.

Examples:
config.columns[:price].calculate = :sum
config.columns[:price].calculate = :avg

clear_link v1.1

Clears out any existing link, and prevents ActiveScaffold from automatically adding a nesting link.

collapsed

Defines whether the column initializes in a collapsed state. Currently collapsing is only supported for association columns on the Create/Update forms.

css_class

An extra css class to apply to this column. Currently used in List.

description

A short description or example text. Currently used in Update/Create.

config.columns[:name].description = "Enter the users first and last name"

form_ui v1.1

If a column has multiple supported form interfaces, you may pick an option here. The options depend on the column type.

For association columns, you may pick :crud (default), or :select. :crud renders the whole subform that lets you actually create/update associated records. :select is a simplification that renders a select box or a collection of checkboxes.

For all other columns, you may pick:

:calendar (this requires a calendar plugin, again plugin specifics can be passed via the Column#options hash )

:checkbox (useful for boolean type columns)

:country (accepts :priority in the Column#options hash)

:password

:textarea (accepts :cols and :rows in the Column#options hash)

:usa_state (accepts :priority in the Column#options hash)

includes

An array of associations for eager loading that are relevant for this column. For association columns, defaults to the association itself. This is especially useful with virtual columns. Consider the following example:

# last_transaction_date is a virtual column that references a joined field 

active_scaffold :users do | config |
  config.columns = [:name, :last_transaction_date, :status]  
  config.columns[:last_transaction_date] = "Last transaction date"
  config.columns[:last_transaction_date].includes = [:user_transactions]
  config.columns[:last_transaction_date].sort_by :sql => "user_transactions.created_at"
end

inplace_edit v1.1

Enable in_place_editor for this column (true or false). Defaults to false. Validation errors are reported via page.alert.

label

The displayable name.

config.columns[:created_at].label = "How Old"

set_link

Sets the action link for this column. Currently used only in List. See action links for options. This link will automatically get the id of the current row, but if you want to put any other dynamic values in the link you’re better off just using a field override.

required

A boolean for whether the column is required through already-existing validation. Currently used in Update/Create.

search_sql

The SQL string used when searching on this column. Defaults to the field name of the column (for real columns). This SQL is the left side of a condition, which means that if you want to do something with multiple fields they have to be in a function.

# good. this will get turned into "WHERE name = ?"
config.columns[:name].search_sql = 'name'

# bad. this will get turned into "WHERE first_name OR last_name = ?", which is invalid syntax
config.columns[:name].search_sql = 'first_name OR last_name = ?'

# good. this will get turned into "WHERE CONCAT(first_name, ' ', last_name) = ?"
config.columns[:name].search_sql = "CONCAT(first_name, ' ', last_name)"

Note: After you define the search_sql you may need to add the column to the searchable columns set.

sort

A boolean for whether this column is sortable or not. Defaults to false for virtual columns.

sort_by

Lets you define either the SQL used for sorting (defaults to the field name) or a string for method based sorting.

# To sort by an SQL expression
columns[:name].sort_by :sql => 'concat(first_name, last_name)'

# to sort by a Ruby method (notice this is a method on the model you are scaffolding against):
columns[:name].sort_by :method => 'full_name'

# If your method sorting can return nil, then you may need to typecast:
columns[:name].sort_by :method => :method => 'full_name or String.new'

Association columns default to using method-based sorting.

Warning: method-based sorting is slow and resource-intensive. The entire table must be loaded and sorted, which will not scale for large data sets. Try to use sort_by :sql as much as possible.

ui_type v1.0 only

Deprecated: in version 1.1 this is an alias for form_ui. In version 1.2 it will be removed entirely.

If a column has multiple supported form interfaces, you may pick an option here. Currently used for association columns. The default interface lets you not only (dis)associate records, but also edit the associated records. If you just want a simple interface to (dis)associate records, then set ui_type = :select.