module ActiveScaffold::Bridges::RecordSelect::Helpers::FormColumnHelpers

Public Instance Methods

active_scaffold_input_record_select(column, options) click to toggle source

requires RecordSelect plugin to be installed and configured.

# File lib/active_scaffold/bridges/record_select/helpers.rb, line 12
def active_scaffold_input_record_select(column, options)
  if column.singular_association?
    multiple = false
    multiple = column.options[:html_options][:multiple] if column.options[:html_options] &&  column.options[:html_options][:multiple]
    active_scaffold_record_select(column, options, @record.send(column.name), multiple)
  elsif column.plural_association?
    active_scaffold_record_select(column, options, @record.send(column.name), true)
  else
    active_scaffold_record_select_autocomplete(column, options)
  end
end
active_scaffold_record_select(column, options, value, multiple) click to toggle source
# File lib/active_scaffold/bridges/record_select/helpers.rb, line 24
def active_scaffold_record_select(column, options, value, multiple)
  unless column.association
    raise ArgumentError, "record_select can only work against associations (and #{column.name} is not).  A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)."
  end
  klass = if column.polymorphic_association?
    @record.send(column.association.foreign_type).constantize rescue nil
  else
    column.association.klass
  end
  return content_tag :span, '', :class => options[:class] unless klass

  remote_controller = active_scaffold_controller_for(klass).controller_path

  # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many)
  # then only show records that have not been associated yet
  if [:has_one, :has_many].include?(column.association.macro)
    params.merge!({column.association.foreign_key => ''})
  end
 
  record_select_options = active_scaffold_input_text_options(options).merge(
    :controller => remote_controller
  )
  record_select_options.merge!(column.options)
 
  html = if multiple
    record_multi_select_field(options[:name], value || [], record_select_options)
  else
    record_select_field(options[:name], value || klass.new, record_select_options)
  end
  html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any?
  html
end
active_scaffold_record_select_autocomplete(column, options) click to toggle source
# File lib/active_scaffold/bridges/record_select/helpers.rb, line 57
def active_scaffold_record_select_autocomplete(column, options)
  record_select_options = active_scaffold_input_text_options(options).merge(
    :controller => active_scaffold_controller_for(@record.class).controller_path
  )
  html = record_select_autocomplete(options[:name], @record, record_select_options)
  html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any?
  html
end