Module: Ruflet::Rails::FormHelpers

Defined in:
lib/ruflet/rails/form_helpers.rb

Instance Method Summary collapse

Instance Method Details

#ruflet_form_attributes(bindings, form_fields) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/ruflet/rails/form_helpers.rb', line 16

def ruflet_form_attributes(bindings, form_fields)
  bindings.to_h do |name, binding|
    field = form_fields.find { |candidate| candidate[:name] == name }
    control = binding[:input] || binding[:control] || binding
    [name, ruflet_control_value(control, field[:type])]
  end
end

#ruflet_form_bindings(record, form_fields) ⇒ Object



6
7
8
9
10
# File 'lib/ruflet/rails/form_helpers.rb', line 6

def ruflet_form_bindings(record, form_fields)
  form_fields.to_h do |field|
    [field[:name], ruflet_field_binding(field, record)]
  end
end

#ruflet_form_controls(bindings) ⇒ Object



12
13
14
# File 'lib/ruflet/rails/form_helpers.rb', line 12

def ruflet_form_controls(bindings)
  bindings.values.map { |binding| binding[:control] }
end

#ruflet_show_errors(record) ⇒ Object



24
25
26
# File 'lib/ruflet/rails/form_helpers.rb', line 24

def ruflet_show_errors(record)
  ruflet_show_snackbar(ruflet_error_message(record))
end

#ruflet_show_snackbar(message) ⇒ Object



28
29
30
# File 'lib/ruflet/rails/form_helpers.rb', line 28

def ruflet_show_snackbar(message)
  page.snackbar = snackbar(text(message), open: true)
end