Whether to enable add_existing for this column
the association from the ActiveRecord class
define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do.
Whether this column set is collapsed by default in contexts where collapsing is supported
the ConnectionAdapter::*Column object from the ActiveRecord class
this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names.
a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example.
supported options:
* for association columns * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
a collection of associations to pre-load when finding the records on a page
Whether to enable inplace editing for this column. Currently works for text columns, in the List.
the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form. if left alone it will utilize human_attribute_name which includes localization
to cache method to get value in list
this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute ... all others will be inferred from this name.
cache constraints for numeric columns (get in ActiveScaffold::Helpers::FormColumnHelpers::numerical_constraints_for_column)
a place to store dev's column specific options
A placeholder text, to be used inside blank text fields to describe, what should be typed in
whether the field is required or not. used on the form for visually indicating the fact to the user. TODO: move into predicate
a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded
What columns load from main table
the table name from the ActiveRecord class
to modify the default order of columns
# File lib/active_scaffold/data_structures/column.rb, line 362 def <=>(other_column) order_weight = self.weight <=> other_column.weight order_weight != 0 ? order_weight : self.name.to_s <=> other_column.name.to_s end
# File lib/active_scaffold/data_structures/column.rb, line 219 def associated_number? @associated_number end
set an action_link to nested list or inline form in this column
# File lib/active_scaffold/data_structures/column.rb, line 150 def autolink? @autolink end
get whether to run a calculation on this column
# File lib/active_scaffold/data_structures/column.rb, line 164 def calculation? !(@calculate == false or @calculate.nil?) end
this should not only delete any existing link but also prevent column links from being automatically added by later routines
# File lib/active_scaffold/data_structures/column.rb, line 155 def clear_link @link = nil @autolink = false end
# File lib/active_scaffold/data_structures/column.rb, line 43 def description if @description @description else I18n.t name, :scope => [:activerecord, :description, active_record_class.to_s.underscore.to_sym], :default => '' end end
the table.field name for this column, if applicable
# File lib/active_scaffold/data_structures/column.rb, line 394 def field @field ||= quoted_field(field_name) end
just the field (not table.field)
# File lib/active_scaffold/data_structures/column.rb, line 357 def field_name return nil if virtual? @field_name ||= column ? @active_record_class.connection.quote_column_name(column.name) : association.foreign_key end
# File lib/active_scaffold/data_structures/column.rb, line 112 def form_ui @form_ui end
# File lib/active_scaffold/data_structures/column.rb, line 170 def includes=(value) @includes = case value when Array then value else [value] # automatically convert to an array end end
# File lib/active_scaffold/data_structures/column.rb, line 12 def inplace_edit=(value) self.clear_link if value @inplace_edit = value end
# File lib/active_scaffold/data_structures/column.rb, line 37 def label as_(@label) || active_record_class.human_attribute_name(name.to_s) end
# File lib/active_scaffold/data_structures/column.rb, line 132 def link @link = @link.call(self) if @link.is_a? Proc @link end
# File lib/active_scaffold/data_structures/column.rb, line 117 def list_ui @list_ui || @form_ui end
# File lib/active_scaffold/data_structures/column.rb, line 279 def number? @number end
# File lib/active_scaffold/data_structures/column.rb, line 367 def number_to_native(value) return value if value.blank? || !value.is_a?(String) native = '.' # native ruby separator format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {}) specific = case self.options[:format] when :currency I18n.t('number.currency.format', :default => nil) when :size I18n.t('number.human.format', :default => nil) when :percentage I18n.t('number.percentage.format', :default => nil) end format.merge! specific unless specific.nil? unless format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/) value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native) else value end end
Any extra parameters this particular column uses. This is for create/update purposes.
# File lib/active_scaffold/data_structures/column.rb, line 29 def params # lazy initialize @params ||= Set.new end
# File lib/active_scaffold/data_structures/column.rb, line 53 def placeholder @placeholder || I18n.t(name, :scope => [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], :default => '') end
# File lib/active_scaffold/data_structures/column.rb, line 254 def plural_association? self.association and [:has_many, :has_and_belongs_to_many].include? self.association.macro end
# File lib/active_scaffold/data_structures/column.rb, line 260 def polymorphic_association? self.association and self.association.options.has_key? :polymorphic and self.association.options[:polymorphic] end
# File lib/active_scaffold/data_structures/column.rb, line 263 def readonly_association? if self.association if self.association.options.has_key? :readonly self.association.options[:readonly] else self.through_association? end end end
# File lib/active_scaffold/data_structures/column.rb, line 63 def required? @required end
a collection of associations to do left join when this column is included on search
# File lib/active_scaffold/data_structures/column.rb, line 178 def search_joins @search_joins || @includes end
# File lib/active_scaffold/data_structures/column.rb, line 182 def search_joins=(value) @search_joins = case value when Array then value else [value] # automatically convert to an array end end
# File lib/active_scaffold/data_structures/column.rb, line 199 def search_sql self.initialize_search_sql if @search_sql === true @search_sql end
describes how to search on a column
search = true default, uses intelligent search sql search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold. search = [:a, :b] searches in both fields
# File lib/active_scaffold/data_structures/column.rb, line 196 def search_sql=(value) @search_sql = (value == true || value.is_a?(Proc)) ? value : Array(value) end
# File lib/active_scaffold/data_structures/column.rb, line 122 def search_ui @search_ui || @form_ui || (@association && !polymorphic_association? ? :select : nil) end
# File lib/active_scaffold/data_structures/column.rb, line 203 def searchable? search_sql != false && search_sql != nil end
associate an action_link with this column
# File lib/active_scaffold/data_structures/column.rb, line 138 def set_link(action, options = {}) if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc) @link = action else options[:label] ||= self.label options[:position] ||= :after unless options.has_key?(:position) options[:type] ||= :member @link = ActiveScaffold::DataStructures::ActionLink.new(action, options) end end
# File lib/active_scaffold/data_structures/column.rb, line 227 def show_blank_record?(associated) if @show_blank_record return false unless self.association.klass.authorized_for?(:crud_type => :create) self.plural_association? or (self.singular_association? and associated.blank?) end end
# File lib/active_scaffold/data_structures/column.rb, line 251 def singular_association? self.association and [:has_one, :belongs_to].include? self.association.macro end
# File lib/active_scaffold/data_structures/column.rb, line 94 def sort self.initialize_sort if @sort === true @sort end
sorting on a column can be configured four ways:
sort = true default, uses intelligent sorting sql default sort = false sometimes sorting doesn't make sense sort = {:sql => ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending. sort = {:method => ""} define ruby-side code for sorting. this is SLOW with large recordsets!
# File lib/active_scaffold/data_structures/column.rb, line 85 def sort=(value) if value.is_a? Hash value.assert_valid_keys(:sql, :method) @sort = value else @sort = value ? true : false # force true or false end end
a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
# File lib/active_scaffold/data_structures/column.rb, line 104 def sort_by(options) self.sort = options end
# File lib/active_scaffold/data_structures/column.rb, line 99 def sortable? sort != false && !sort.nil? end
# File lib/active_scaffold/data_structures/column.rb, line 257 def through_association? self.association and self.association.options[:through] end
update dependent columns after value change in form
update_columns = :name update_columns = [:name, :age]
# File lib/active_scaffold/data_structures/column.rb, line 72 def update_columns=(column_names) @update_columns = Array(column_names) end
an interpreted property. the column is virtual if it isn't from the active record model or any associated models
# File lib/active_scaffold/data_structures/column.rb, line 274 def virtual? column.nil? && association.nil? end
# File lib/active_scaffold/data_structures/column.rb, line 430 def estimate_weight if singular_association? 400 elsif plural_association? 500 elsif [:created_at, :updated_at].include?(self.name) 600 elsif [:name, :label, :title].include?(self.name) 100 elsif required? 200 else 300 end end
# File lib/active_scaffold/data_structures/column.rb, line 417 def initialize_search_sql self.search_sql = unless self.virtual? if association.nil? self.field.to_s unless @tableless elsif !self.polymorphic_association? [association.klass.quoted_table_name, association.klass.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless end end end
# File lib/active_scaffold/data_structures/column.rb, line 404 def initialize_sort if self.virtual? # we don't automatically enable method sorting for virtual columns because it's slow, and we expect fewer complaints this way. self.sort = false else if column && !@tableless self.sort = {:sql => self.field} else self.sort = false end end end
# File lib/active_scaffold/data_structures/column.rb, line 400 def quoted_field(name) [@active_record_class.quoted_table_name, name].join('.') end