Module: ActiveScaffold::Bridges::RecordSelect::Helpers::FormColumnHelpers
- Defined in:
- lib/active_scaffold/bridges/record_select/helpers.rb
Instance Method Summary collapse
-
#active_scaffold_input_record_select(column, options, ui_options: column.options) ⇒ Object
requires RecordSelect plugin to be installed and configured.
- #active_scaffold_record_select(record, column, options, value, multiple, ui_options: column.options) ⇒ Object
- #active_scaffold_record_select_autocomplete(record, column, options, ui_options: column.options) ⇒ Object
Instance Method Details
#active_scaffold_input_record_select(column, options, ui_options: column.options) ⇒ Object
requires RecordSelect plugin to be installed and configured.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_scaffold/bridges/record_select/helpers.rb', line 13 def active_scaffold_input_record_select(column, , ui_options: column.) record = .delete(:object) if column.association&.singular? multiple = .dig(:html_options, :multiple) html = active_scaffold_record_select(record, column, , record.send(column.name), multiple, ui_options: ) html << active_scaffold_new_record_subform(column, record, , ui_options: ) if [:add_new] html elsif column.association&.collection? active_scaffold_record_select(record, column, , record.send(column.name), true, ui_options: ) else active_scaffold_record_select_autocomplete(record, column, , ui_options: ) end end |
#active_scaffold_record_select(record, column, options, value, multiple, ui_options: column.options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_scaffold/bridges/record_select/helpers.rb', line 27 def active_scaffold_record_select(record, column, , value, multiple, ui_options: column.) 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 = column.association.klass(record) return content_tag :span, '', class: [: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 params[column.association.foreign_key] = '' if column.association.has_one? || column.association.has_many? = ().merge( controller: remote_controller ) .merge!() html = if multiple record_multi_select_field([:name], value || [], .except(:required)) else record_select_field([:name], value || klass.new, ) end html = instance_exec(html, self, &self.class.field_error_proc) if record.errors[column.name].any? html end |
#active_scaffold_record_select_autocomplete(record, column, options, ui_options: column.options) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/active_scaffold/bridges/record_select/helpers.rb', line 56 def active_scaffold_record_select_autocomplete(record, column, , ui_options: column.) = ().reverse_merge( controller: active_scaffold_controller_for(record.class).controller_path ).merge() html = record_select_autocomplete([:name], record, ) html = instance_exec(html, self, &self.class.field_error_proc) if record.errors[column.name].any? html end |