Module: DynamicFieldsets::NestedModelHelper

Included in:
FieldsHelper, FieldsetChildrenHelper
Defined in:
app/helpers/dynamic_fieldsets/nested_model_helper.rb

Instance Method Summary collapse

Instance Method Details

returns a link with an onclick call to add_fields the field information is rendered from a partial and stored as a string until it is needed



10
11
12
13
14
15
16
# File 'app/helpers/dynamic_fieldsets/nested_model_helper.rb', line 10

def df_link_to_add_fields(name, f, association, method = "add_fields")  
  new_object = f.object.class.reflect_on_association(association).klass.new  
  fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|  
    render(association.to_s.singularize + "_fields", {:f => builder, :obj => new_object})  
  end  
  link_to_function(name, "#{method}(this, '#{association}', '#{escape_javascript(fields)}')", {:class => name.underscore.gsub(' ', '_')})
end

returns a link with an onclick call to remove_fields using link_to_function



4
5
6
# File 'app/helpers/dynamic_fieldsets/nested_model_helper.rb', line 4

def df_link_to_remove_fields(name, f)  
  f.hidden_field(:_destroy) + link_to_function(name, {:onclick => "remove_fields(this)"})  
end