Class: FormForms::Forms::BaseForm

Inherits:
Elements::BaseElement show all
Defined in:
lib/form_forms/forms/base_form.rb

Overview

The generic top-level form for building a simple_form..

This class (and all its children) is only usable as a top-level form as it generates its own form builder object which is passed to its sub-elements on rendering

Direct Known Subclasses

Form

Instance Attribute Summary

Attributes inherited from Elements::BaseElement

#elements

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Elements::BaseElement

#delete

Constructor Details

#initialize(form_args = {}) ⇒ BaseForm

form_args are passed to the initializer of the form builder. They can be used to override its defaults.



11
12
13
14
# File 'lib/form_forms/forms/base_form.rb', line 11

def initialize(form_args = {})
  @form_args = form_args
  super
end

Class Method Details

.register(name, form_args = {}, &generator) ⇒ Object



35
36
37
# File 'lib/form_forms/forms/base_form.rb', line 35

def self.register(name, form_args={}, &generator)
  ::FormForms::FormRegistry[name] = self.new(form_args, &generator)
end

Instance Method Details

#args(form_args = nil) ⇒ Object

Set the form_args. These are static as we don’t have a form yet



17
18
19
20
21
22
23
# File 'lib/form_forms/forms/base_form.rb', line 17

def args(form_args=nil)
  if form_args
    @form_args = form_args
  else
    @form_args
  end
end

#render(model, view) ⇒ Object

Render the form. Notice that forms receive an ActiveModel object as its first parameter, unlike elements which receive the form builder which is created by a form.



29
30
31
32
33
# File 'lib/form_forms/forms/base_form.rb', line 29

def render(model, view)
  view.simple_form_for(model, self.args) do |builder|
    render_elements(builder, view)
  end
end