Sha256: 50ad74924ded5c769ac6f4539e6b4c96eec0780b68bc68de55014b7d256a3077
Contents?: true
Size: 969 Bytes
Versions: 11
Compression:
Stored size: 969 Bytes
Contents
module DynamicFieldsets module NestedModelHelper # returns a link with an onclick call to remove_fields using link_to_function def df_link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, {:onclick => "remove_fields(this)"}) end # 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 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 end end
Version data entries
11 entries across 11 versions & 1 rubygems