Module: Lotus::Helpers::FormHelper
- Defined in:
- lib/lotus/helpers/form_helper.rb,
lib/lotus/helpers/form_helper/values.rb,
lib/lotus/helpers/form_helper/html_node.rb,
lib/lotus/helpers/form_helper/form_builder.rb
Overview
Form builder
By including Lotus::Helpers::FormHelper
it will inject one public method: form_for
. This is a HTML5 form builder.
To understand the general HTML5 builder syntax of this framework, please consider to have a look at Lotus::Helpers::HtmlHelper
documentation.
This builder is independent from any template engine. This was hard to achieve without a compromise: the form helper should be used in one output block in a template or as a method in a view (see the examples below).
Features:
* Support for complex markup without the need of concatenation
* Auto closing HTML5 tags
* Support for view local variables
* Method override support (PUT/PATCH/DELETE HTTP verbs aren't understood by browsers)
* Automatic generation of HTML attributes for inputs: <tt>id</tt>, <tt>name</tt>, <tt>value</tt>
* Allow to override HTML attributes
* Extract values from request params and fill <tt>value</tt> attributes
* Automatic selection of current value for radio button and select inputs
* Infinite nested fields
Supported tags and inputs:
* <tt>color_field</tt>
* <tt>date_field</tt>
* <tt>datetime_field</tt>
* <tt>datetime_local_field</tt>
* <tt>email_field</tt>
* <tt>hidden_field</tt>
* <tt>file_field</tt>
* <tt>fields_for</tt>
* <tt>form_for</tt>
* <tt>label</tt>
* <tt>text_area</tt>
* <tt>text_field</tt>
* <tt>password_field</tt>
* <tt>radio_button</tt>
* <tt>select</tt>
* <tt>submit</tt>
Defined Under Namespace
Classes: Form, FormBuilder, HtmlNode, Values
Constant Summary collapse
- DEFAULT_METHOD =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default HTTP method for form
'POST'.freeze
- DEFAULT_CHARSET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default charset
'utf-8'.freeze
- CSRF_TOKEN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
CSRF Token session key
This key is shared with
lotusrb
,lotus-controller
. :_csrf_token
Instance Method Summary collapse
-
#csrf_token ⇒ String, NilClass
Returns CSRF Protection Token stored in session.
-
#form_for(name, url, options = {}, &blk) ⇒ Lotus::Helpers::FormHelper::FormBuilder
Instantiate a HTML5 form builder.
Instance Method Details
#csrf_token ⇒ String, NilClass
Returns CSRF Protection Token stored in session.
It returns nil
if sessions aren’t enabled or the value is missing.
415 416 417 418 419 420 421 |
# File 'lib/lotus/helpers/form_helper.rb', line 415 def csrf_token if defined?(session) session[CSRF_TOKEN] elsif defined?(locals) && locals[:session] locals[:session][CSRF_TOKEN] end end |
#form_for(name, url, options, &blk) ⇒ Lotus::Helpers::FormHelper::FormBuilder #form_for(form, attributes, &blk) ⇒ Lotus::Helpers::FormHelper::FormBuilder
Instantiate a HTML5 form builder
396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/lotus/helpers/form_helper.rb', line 396 def form_for(name, url, = {}, &blk) form = if name.is_a?(Form) = url name else Form.new(name, url, .delete(:values)) end attributes = { action: form.url, method: form.verb, :'accept-charset' => DEFAULT_CHARSET, id: "#{ form.name }-form" }.merge() FormBuilder.new(form, attributes, self, &blk) end |