Class: Sipity::Forms::BaseForm

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Translation
Includes:
ActiveModel::Validations
Defined in:
app/forms/sipity/forms/base_form.rb

Overview

A Form data structure for validation and submission.

I'm including persistence related methods so this behaves “well enough” for a Rails form_for (or simple_form_for) tag.

Instance Method Summary collapse

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/forms/sipity/forms/base_form.rb', line 24

def persisted?
  to_param.nil? ? false : true
end

#submit {|BaseForm| ... } ⇒ Object

Yields:

  • (BaseForm)

    when the form is valid yield control to the caller

Yield Parameters:

Yield Returns:

  • the sender's response successful

Returns:

  • false if the form was not valid

  • truthy if the form was valid and the caller's submission block was successful



36
37
38
39
# File 'app/forms/sipity/forms/base_form.rb', line 36

def submit
  return false unless valid?
  return yield(self)
end

#to_keyObject



16
17
18
# File 'app/forms/sipity/forms/base_form.rb', line 16

def to_key
  []
end

#to_paramObject



20
21
22
# File 'app/forms/sipity/forms/base_form.rb', line 20

def to_param
  nil
end