Sha256: e3470248d32818927c40e14f5e0f27c509762efcbba5aef2f0455ab4eeb372d0

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Para
  module FormHelper
    def para_form_for(resource, options = {}, &block)
      default_options = {
        as: :resource,
        wrapper: :vertical_form,
        wrapper_mappings: Para::SimpleFormConfig.wrapper_mappings,
        html: { class: '', data: { :'para-form' => true } }
      }

      options = default_options.deep_merge(options)

      options[:html][:class] = [
        options[:html][:class].presence,
        'form-vertical forms-outline'
      ].compact.join(' ')

      unless options.key?(:url)
        options[:url] = @component.relation_path(resource)
      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

          content << form.attributes_mappings_field_for(form)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
para-0.7.0 app/helpers/para/form_helper.rb