Module: Para::FormHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/para/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#para_form_for(resource, options = {}, &block) ⇒ 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
29
30
31
32
33
34
# File 'app/helpers/para/form_helper.rb', line 3

def para_form_for(resource, options = {}, &block)
  default_options = {
    as: :resource,
    wrapper: :horizontal_form,
    html: { class: '', data: { :'para-form' => true } }
  }

  options = default_options.deep_merge(options)

  options[:html][:class] = [
    options[:html][:class].presence,
    'form-horizontal form-group-separated'
  ].compact.join(' ')

  unless options.key?(:url)
    options[:url] = @component.relation_path(resource)
  end

  if options.fetch(:fixed_actions, true)
    default_options[:html][:class] << ' form-fixed-actions'
  end

  simple_form_for(resource, options) do |form|
    capture { block.call(form) }.tap do |content|
      # Append hidden field with type if resource is subclassable
      # to avoid bad class instantiation in create action
      if @component.subclassable? && resource.new_record?
        content << form.hidden_field(:type, value: resource.type)
      end
    end
  end
end