Class: FormForms::Elements::Field
- Inherits:
-
BaseElement
- Object
- BaseElement
- FormForms::Elements::Field
- Defined in:
- lib/form_forms/elements/field.rb
Overview
This represents a single form field. Typically this is the most low-level part of a form. You can either return a form element with the help of the passed form builder or just return arbitrary html. The block is executed in the scope of the view where the form is rendered. You can use any helpers defined there.
Note that you might need to mark your values as html_safe
to avoid superfluous escaping in the view.
Example:
my_form = Form.new() do |form|
form.field(:subject) {|f| f.input :subject}
form.field(:link) do |f|
content_tag :p do
content_tag(:a, :href => hint_path){ "This is a hint" }
end
end
end
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseElement
Instance Method Summary collapse
-
#initialize(&generator) ⇒ Field
constructor
A new instance of Field.
- #render(builder, view) ⇒ Object
Methods inherited from BaseElement
Constructor Details
#initialize(&generator) ⇒ Field
Returns a new instance of Field.
23 24 25 |
# File 'lib/form_forms/elements/field.rb', line 23 def initialize(&generator) self.generator generator end |
Instance Method Details
#render(builder, view) ⇒ Object
29 30 31 |
# File 'lib/form_forms/elements/field.rb', line 29 def render(builder, view) eval_property(:generator, builder, view) end |