class Presentation::Form

Attributes

button[W]
html[RW]

a passthrough for form_for’s html. useful for classifying a form for ajax behavior (e.g. :html => {:class => ‘ajax’})

method[W]
url[W]

Public Instance Methods

button() click to toggle source

the text on the submit button

# File lib/presentation/form.rb, line 95
def button
  @button ||= presentable.new_record? ? 'Create' : 'Update'
end
fields() click to toggle source

Used to define fields in a group-less form.

# File lib/presentation/form.rb, line 68
def fields
  if groups.empty?
    groups << []
  end
  groups.first.fields
end
fields=(args) click to toggle source
# File lib/presentation/form.rb, line 74
def fields=(args)
  args.each do |field|
    fields << field
  end
end
groups() click to toggle source

Fields may be grouped. Groups may or may not have names. Here’s how:

Presentation::Form.new(:groups => [
  [:a, :b],             # creates a nameless group with fields :a and :b
  {"foo" => [:c, :d]}   # creates a group named "foo" with fields :c and :d
])

Note that if you don’t need groups it’ll be simpler to just use fields= instead.

# File lib/presentation/form.rb, line 30
def groups
  @groups ||= GroupSet.new
end
groups=(args) click to toggle source
# File lib/presentation/form.rb, line 33
def groups=(args)
  args.each do |group|
    groups << group
  end
end
iname() click to toggle source
# File lib/presentation/form.rb, line 145
def iname; :form end
method() click to toggle source

What method the form should use to post. Should default intelligently enough from the presentable. Not sure what use case would require it being set manually.

# File lib/presentation/form.rb, line 89
def method
  @method ||= presentable.new_record? ? :post : :put
end
url() click to toggle source

The url where the form posts. May be anything that url_for accepts, including a set of records.

# File lib/presentation/form.rb, line 82
def url
  @url ||= presentable
end