Created
July 24, 2010 03:00
-
-
Save guitsaru/488349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.action.new[data-content][data-association]').click(function () { | |
var new_id = new Date().getTime(); | |
var regexp = new RegExp("new_" + $(this).attr('data-association'), "g"); | |
$(this).before($(this).attr('data-content').replace(regexp, new_id)); | |
return false; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def new_object_fields(f, association) | |
new_object = f.object.class.reflect_on_association(association).klass.new | |
f.fields_for(association, new_object, :child_index => "new_#{association.to_s.singularize}") do |builder| | |
render(:partial => "#{association.to_s.singularize}_fields", :locals => {:f => builder}) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= form_for @parent do |f| | |
%h3 Children | |
%fieldset.children | |
= fields_for :children do |children_form| | |
= render :partial => 'parent/children_fields', :locals => {:f => children_form} | |
= link_to 'Add Child', '#', :class => 'action new', 'data-association' => 'child', 'data-content' => new_object_fields(f, :children) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment