Class: Parlez::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Parlez::FormBuilder
- Defined in:
- lib/parlez/form_builder.rb
Instance Method Summary collapse
- #errors_on(method) ⇒ Object
- #label_for(field, options) ⇒ Object
- #rich_area(field, options = {}) ⇒ Object
- #structured_field(type, field, options = {}, &block) ⇒ Object
- #submit(value, options = {}, &block) ⇒ Object
Instance Method Details
#errors_on(method) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/parlez/form_builder.rb', line 48 def errors_on(method) if object and object.respond_to?(:errors) if object.errors[method].present? errors = object.errors[method] "<div class='error_message'>#{errors.is_a?(Array) ? errors.first : errors}</div>" end end end |
#label_for(field, options) ⇒ Object
33 34 35 36 |
# File 'lib/parlez/form_builder.rb', line 33 def label_for(field, ) label = .delete(:label) || field.to_s.titleize "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe end |
#rich_area(field, options = {}) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/parlez/form_builder.rb', line 18 def rich_area(field, = {}) .merge!({:class => 'rich_text'}) structured_field 'text_area', field, do text_area(field, ) end end |
#structured_field(type, field, options = {}, &block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/parlez/form_builder.rb', line 25 def structured_field(type, field, = {}, &block) out = "<div class='form_field #{type}'>" out << "<div class='label'>#{label_for(field, )}</div>" if ![:omit_label] out << "<div class='field'>#{errors_on(field)}#{yield}</div>" out << "</div>" out.html_safe end |
#submit(value, options = {}, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/parlez/form_builder.rb', line 38 def submit(value, = {}, &block) extra_content = @template.capture(&block) if block_given? cancel_link ||= [:cancel_url] ? ' or ' + .delete(:cancel_url) : '' %( <div class='form_element submit_element'> #{super(value, )} #{extra_content} #{cancel_link} </div> ).html_safe end |