Class: Hanami::Helpers::FormHelper::Form
- Inherits:
-
Object
- Object
- Hanami::Helpers::FormHelper::Form
- Defined in:
- lib/hanami/helpers/form_helper.rb
Overview
Form object
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
private
The form name.
-
#url ⇒ String
readonly
private
The form action.
-
#values ⇒ ::Hash
readonly
private
The form values.
Instance Method Summary collapse
-
#initialize(name, url, values = {}, attributes = {}) ⇒ Form
constructor
Initialize a form.
-
#verb ⇒ String
private
Return the method specified by the given attributes or fall back to the default value.
Constructor Details
#initialize(name, url, values = {}, attributes = {}) ⇒ Form
Initialize a form
It accepts a set of values that are used in combination with request params to autofill value
attributes for fields.
The keys of this Hash, MUST correspond to the structure of the (nested) fields of the form.
For a given input where the name
is ‘book`, Hanami will look for `:book` key in values.
If the current params have the same key, it will be PREFERRED over the given values.
For instance, if params.get('book.title')
equals to "TDD"
while values[:book].title
returns "No test"
, the first will win.
203 204 205 206 207 208 |
# File 'lib/hanami/helpers/form_helper.rb', line 203 def initialize(name, url, values = {}, attributes = {}) @name = name @url = url @values = values @attributes = attributes || {} end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the form name.
111 112 113 |
# File 'lib/hanami/helpers/form_helper.rb', line 111 def name @name end |
#url ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the form action.
117 118 119 |
# File 'lib/hanami/helpers/form_helper.rb', line 117 def url @url end |
#values ⇒ ::Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the form values.
123 124 125 |
# File 'lib/hanami/helpers/form_helper.rb', line 123 def values @values end |
Instance Method Details
#verb ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the method specified by the given attributes or fall back to the default value
219 220 221 |
# File 'lib/hanami/helpers/form_helper.rb', line 219 def verb @attributes.fetch(:method, DEFAULT_METHOD) end |