Module: FormFu::Helpers
- Defined in:
- lib/form_fu/helpers.rb
Instance Method Summary collapse
-
#field_tag(options_or_label = {}, content = nil, &block) ⇒ Object
generate a field div with label.
-
#fieldset_tag(legend_name, options = {}, &block) ⇒ Object
wrap content with a fieldset tag with a legend.
-
#formfu_fields_for(object_or_object_name, *args) {|FormFu::FormBuilder.new(object_name, object, self, options, block)| ... } ⇒ Object
(also: #build_fields_for)
Create a fields_for block using FormFuBuilder.
-
#formfu_for(record_or_name_or_array, *args, &proc) ⇒ Object
(also: #build_form_for)
Create a form_for block using FormFuBuilder.
-
#validation_tag(model, attribute, options = {}) ⇒ Object
show validation error is applicable.
Instance Method Details
#field_tag(options_or_label = {}, content = nil, &block) ⇒ Object
generate a field div with label
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/form_fu/helpers.rb', line 49 def field_tag( = {}, content = nil, &block) label, = "", {} if .class == String label = [:class] = "field" else = # grab the error indicator out of the options has_error = .delete(:has_error) || false # grab the field_type out of the options field_type = .delete(:field_type) || nil # append field as css class for div options [:class] = "field #{field_type} #{[:class]} #{'withErrors' if has_error}" end if block_given? concat(content_tag(:div, ) do (label.blank? ? "" : content_tag(:label, label.strip)) + capture(&block) end, block.binding) else content_tag(:div, ) do (label.blank? ? "" : content_tag(:label, label.strip))+content.to_s end end end |
#fieldset_tag(legend_name, options = {}, &block) ⇒ Object
wrap content with a fieldset tag with a legend
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/form_fu/helpers.rb', line 35 def fieldset_tag(legend_name, = {}, &block) if block_given? concat(content_tag(:fieldset, ) do (legend_name ? content_tag(:legend, legend_name) : "")+ capture(&block) end, block.binding) else return content_tag(:fieldset, ) do content_tag :legend, legend_name end end end |
#formfu_fields_for(object_or_object_name, *args) {|FormFu::FormBuilder.new(object_name, object, self, options, block)| ... } ⇒ Object Also known as: build_fields_for
Create a fields_for block using FormFuBuilder
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/form_fu/helpers.rb', line 14 def formfu_fields_for(object_or_object_name, *args, &block) raise ArgumentError, "Missing block" unless block_given? = args. if object_or_object_name.class == Symbol # if object_or_object_name is a symbol, use the object from args object_name = object_or_object_name object = args.first else # otherwise retrieve the object_name from ActiveRecord helper object = object_or_object_name object_name = ActionController::RecordIdentifier.singular_class_name(object) end yield FormFu::FormBuilder.new(object_name, object, self, , block) end |
#formfu_for(record_or_name_or_array, *args, &proc) ⇒ Object Also known as: build_form_for
Create a form_for block using FormFuBuilder
4 5 6 7 8 |
# File 'lib/form_fu/helpers.rb', line 4 def formfu_for(record_or_name_or_array, *args, &proc) = args. args << .merge(:builder => FormFu::FormBuilder) form_for(record_or_name_or_array, *args, &proc) end |
#validation_tag(model, attribute, options = {}) ⇒ Object
show validation error is applicable
79 80 81 82 83 84 85 86 87 |
# File 'lib/form_fu/helpers.rb', line 79 def validation_tag(model, attribute, = {}) return if model.blank? or model.errors.blank? unless model.errors[attribute].blank? # generate error markup content_tag :span, :class => "error-message" do [model.errors[attribute]].flatten.join([:separator] || ", ").to_s end end end |