Module: Forms::FormsHelper
- Defined in:
- app/helpers/forms/forms_helper.rb
Defined Under Namespace
Classes: FormBuilder
Instance Method Summary collapse
- #field_template(id, klass) ⇒ Object
- #form_field(field, options = {}, &block) ⇒ Object
- #render_fields(fields, prefix) ⇒ Object
Instance Method Details
#field_template(id, klass) ⇒ Object
31 32 33 34 35 |
# File 'app/helpers/forms/forms_helper.rb', line 31 def field_template(id, klass) jquery_template_tag(id) do render :partial => klass.partial, :object => klass.new, :locals => { :index => "${index}", :prefix => "${prefix}" } end end |
#form_field(field, options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/forms/forms_helper.rb', line 10 def form_field(field, ={}, &block) builder = FormBuilder.new([:prefix], field, self, {}, block) icon = [:icon] || field.class.model_name.demodulize.underscore.dasherize content_tag(:div, :class => [:class], :data => { :index => [:index] }) do concat builder.hidden_field(:type, :value => field.type.demodulize, :id => nil) concat content_tag(:div, image_tag("wheelhouse-forms/#{icon}.png", :alt => field.class.model_name.human, :title => field.class.model_name.human), :class => "drag") concat content_tag(:div, capture(builder, &block), :class => "drag-area") concat link_to("Delete", '#', :class => 'delete') end end |
#render_fields(fields, prefix) ⇒ Object
25 26 27 28 29 |
# File 'app/helpers/forms/forms_helper.rb', line 25 def render_fields(fields, prefix) fields.map_with_index do |field, index| render(:partial => field.class.partial, :object => field, :locals => { :index => index, :prefix => "#{prefix}[#{index}]" }) end.join("\n").html_safe end |