Class: Presentation::Form
Defined Under Namespace
Classes: Field, Group, GroupSet
Instance Attribute Summary collapse
-
#button ⇒ Object
the text on the submit button.
-
#html ⇒ Object
a passthrough for form_for’s html.
-
#method ⇒ Object
What method the form should use to post.
-
#url ⇒ Object
The url where the form posts.
Attributes inherited from Base
Instance Method Summary collapse
-
#fields ⇒ Object
Used to define fields in a group-less form.
- #fields=(args) ⇒ Object
-
#groups ⇒ Object
Fields may be grouped.
- #groups=(args) ⇒ Object
- #iname ⇒ Object
-
#protect_against_forgery? ⇒ Boolean
:nodoc:.
Methods inherited from Base
Methods included from Presenting::Configurable
Instance Attribute Details
#button ⇒ Object
the text on the submit button
95 96 97 |
# File 'lib/presentation/form.rb', line 95 def @button ||= presentable.new_record? ? 'Create' : 'Update' end |
#html ⇒ Object
a passthrough for form_for’s html. useful for classifying a form for ajax behavior (e.g. :html => => ‘ajax’)
101 102 103 |
# File 'lib/presentation/form.rb', line 101 def html @html end |
#method ⇒ Object
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.
89 90 91 |
# File 'lib/presentation/form.rb', line 89 def method @method ||= presentable.new_record? ? :post : :put end |
#url ⇒ Object
The url where the form posts. May be anything that url_for accepts, including a set of records.
82 83 84 |
# File 'lib/presentation/form.rb', line 82 def url @url ||= presentable end |
Instance Method Details
#fields ⇒ Object
Used to define fields in a group-less form.
68 69 70 71 72 73 |
# File 'lib/presentation/form.rb', line 68 def fields if groups.empty? groups << [] end groups.first.fields end |
#fields=(args) ⇒ Object
74 75 76 77 78 |
# File 'lib/presentation/form.rb', line 74 def fields=(args) args.each do |field| fields << field end end |
#groups ⇒ Object
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.
30 31 32 |
# File 'lib/presentation/form.rb', line 30 def groups @groups ||= GroupSet.new end |
#groups=(args) ⇒ Object
33 34 35 36 37 |
# File 'lib/presentation/form.rb', line 33 def groups=(args) args.each do |group| groups << group end end |
#iname ⇒ Object
145 |
# File 'lib/presentation/form.rb', line 145 def iname; :form end |
#protect_against_forgery? ⇒ Boolean
:nodoc:
148 149 150 |
# File 'lib/presentation/form.rb', line 148 def protect_against_forgery? #:nodoc: allow_forgery_protection && request_forgery_protection_token end |