Module: ActiveScaffold::RecordSelectBridge::FormColumnHelpers
- Defined in:
- lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb
Instance Method Summary collapse
-
#active_scaffold_input_record_select(column, options) ⇒ Object
requires RecordSelect plugin to be installed and configured.
- #active_scaffold_record_select(column, options, value, multiple) ⇒ Object
Instance Method Details
#active_scaffold_input_record_select(column, options) ⇒ Object
requires RecordSelect plugin to be installed and configured.
23 24 25 26 27 28 29 30 31 |
# File 'lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb', line 23 def active_scaffold_input_record_select(column, ) if column.singular_association? multiple = false multiple = column.[:html_options][:multiple] if column.[:html_options] && column.[:html_options][:multiple] active_scaffold_record_select(column, , @record.send(column.name), multiple) elsif column.plural_association? active_scaffold_record_select(column, , @record.send(column.name), true) end end |
#active_scaffold_record_select(column, options, value, multiple) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb', line 33 def active_scaffold_record_select(column, , 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 remote_controller = active_scaffold_controller_for(column.association.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.primary_key_name => ''}) end = ( :controller => remote_controller, :id => [:id], :class => [:class] ) .merge!(column.) if ['data-update_url'] [:onchange] = %|function(id, label) { ActiveScaffold.update_column($("##{[:id]}"), "#{['data-update_url']}", #{['data-update_send_form'].to_json}, "#{[:id]}", id); }| end html = if multiple record_multi_select_field([:name], value || [], ) else record_select_field([:name], value || column.association.klass.new, ) end html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? html end |