Sha256: 66016ca3a27cf922e7922ced541fde78349b73e7b4583d8ce3ac25e4699d5be4

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

require 'monkey_forms'

class OrderForm
  include MonkeyForms::Form
  attr_reader :an_attribute

  # Declares a few attributes on the form.
  form_attributes :name, :email, :city, :state, :line_items
  custom_attributes :user_id
  form_name :cart

  # This form serializes the submit into a gzip'd cookie with a name
  # of 'order_cookie'.
  set_form_storage(
    MonkeyForms::Serializers::GzipCookie.new(
      :name => 'order_cookie',
      :domain => 'test.domain.com',
      :secure => true,
      :httponly => true))

  after_initialize :set_attribute, :set_default_state

  # We must submit an email address for the form to validate.
  validates :email, :presence => true

  set_form_attribute_human_names :name => "Your Name"

  validation_group :cart do
    # Scope some of the validation checks
    validates :name, :presence => true
  end

  validation_group :address do
    validates :city,  :presence => true
    validates :state, :presence => true
  end

  # This is a method that uses some form attributes.
  def person
    "#{ name } <#{ email }>"
  end

  private

  def set_attribute
    @an_attribute = true
  end

  def set_default_state
    if state.blank?
      self.state = "WA"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
monkey_forms-0.0.18 test/forms/order_form.rb
monkey_forms-0.0.17 test/forms/order_form.rb
monkey_forms-0.0.16 test/forms/order_form.rb
monkey_forms-0.0.15 test/forms/order_form.rb