Class: SofaGallery::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- SofaGallery::FormBuilder
- Defined in:
- lib/sofa_gallery/form_builder.rb
Instance Method Summary collapse
- #default_field(type, field, options = {}, &block) ⇒ Object
- #label_for(field, options) ⇒ Object
- #simple_field(label = nil, content = nil, options = {}, &block) ⇒ Object
Instance Method Details
#default_field(type, field, options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sofa_gallery/form_builder.rb', line 18 def default_field(type, field, = {}, &block) errors = if object.respond_to?(:errors) && object.errors[field].present? "<div class='errors'>#{[object.errors[field]].flatten.first}</div>" end if desc = .delete(:desc) desc = "<div class='desc'>#{desc}</div>" end %( <div class='form_element #{type}_element #{'errors' if errors}'> <div class='label'>#{label_for(field, )}</div> <div class='value'>#{yield}</div> #{desc} #{errors} </div> ).html_safe end |
#label_for(field, options) ⇒ Object
35 36 37 38 |
# File 'lib/sofa_gallery/form_builder.rb', line 35 def label_for(field, ) label = .delete(:label) || field.to_s.titleize.capitalize "<label for=\"#{object_name}_#{field}\">#{label}</label>".html_safe end |
#simple_field(label = nil, content = nil, options = {}, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/sofa_gallery/form_builder.rb', line 40 def simple_field(label = nil, content = nil, = {}, &block) content ||= @template.capture(&block) if block_given? %( <div class='form_element #{.delete(:class)}'> <div class='label'>#{label}</div> <div class='value'>#{content}</div> </div> ).html_safe end |