Module: Voluntary::FormHelper
- Defined in:
- app/helpers/voluntary/form_helper.rb
Instance Method Summary collapse
- #autocomplete_input(f, field, namespace = nil) ⇒ Object
- #link_to_add_fields(name, f, association, options = {}) ⇒ Object
- #remove_fields(f) ⇒ Object
Instance Method Details
#autocomplete_input(f, field, namespace = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/helpers/voluntary/form_helper.rb', line 38 def autocomplete_input(f, field, namespace = nil) if namespace f.input "#{field}_name", input_html: { data: {autocomplete: eval("autocomplete_#{namespace}_#{field.to_s.tableize}_path")} } else f.input "#{field}_name", input_html: { data: {autocomplete: eval("autocomplete_#{field.to_s.tableize}_path")} } end end |
#link_to_add_fields(name, f, association, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/voluntary/form_helper.rb', line 3 def link_to_add_fields(name, f, association, = {}) attributes = { "#{root_model_class_name(f.object).tableize.singularize}".to_sym => f.object } new_object = if f.object.respond_to? "#{association.to_s.singularize}_class" f.object.send("#{association.to_s.singularize}_class").new(attributes) else f.object.send(association).new(attributes) end id = new_object.object_id #fields = f.fields_for(association, new_object, child_index: id) do |builder| fields = f.simple_fields_for(association) do |builder| render_product_specific_partial_if_available( new_object, "#{controller_name}/#{association.to_s.singularize}_fields", f: builder ) end data = {id: id, fields: fields.gsub("\n", '')} data[:target] = [:target] if .has_key?(:target) link_to(name, '#', class: 'add_fields', data: data) end |
#remove_fields(f) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/helpers/voluntary/form_helper.rb', line 30 def remove_fields(f) if f.object.try(:new_record?) link_to t('general.remove'), '#', class: 'remove_fields' else f.check_box(:_destroy) + f.label(:_destroy, t('general.destroy')) end end |