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, &block) ⇒ Object
(also: #build_form_for)
Create a form_for block using FormFuBuilder.
-
#remote_formfu_for(record_or_name_or_array, *args, &block) ⇒ Object
(also: #build_remote_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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/form_fu/helpers.rb', line 67 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
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/form_fu/helpers.rb', line 53 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/form_fu/helpers.rb', line 32 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, &block) ⇒ Object Also known as: build_form_for
Create a form_for block using FormFuBuilder
4 5 6 7 8 9 10 11 |
# File 'lib/form_fu/helpers.rb', line 4 def formfu_for(record_or_name_or_array, *args, &block) raise ArgumentError, "Missing block" unless block_given? = args. args << .merge(:builder => FormFu::FormBuilder) form_for(record_or_name_or_array, *args, &block) end |
#remote_formfu_for(record_or_name_or_array, *args, &block) ⇒ Object Also known as: build_remote_form_for
Create a form_for block using FormFuBuilder
18 19 20 21 22 23 24 25 |
# File 'lib/form_fu/helpers.rb', line 18 def remote_formfu_for(record_or_name_or_array, *args, &block) raise ArgumentError, "Missing block" unless block_given? = args. args << .merge(:builder => FormFu::FormBuilder) remote_form_for(record_or_name_or_array, *args, &block) end |
#validation_tag(model, attribute, options = {}) ⇒ Object
show validation error is applicable
97 98 99 100 101 102 103 104 105 |
# File 'lib/form_fu/helpers.rb', line 97 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 |