Grary
2010-Feb-28 14:52 UTC
nested model form javascript question (re Ryan Bates''s Railscasts #196-7)
Hi,
I might guess there are some loyal fans of Ryan Bates''s Railscasts out
there. For those who might be familiar with his two casts on nested
model forms (#196-7), I had a question...
How do I modify one (or both) of the javascript and helper functions,
respectively, that Ryan showed so that I can use them to append
multiple children? In other words, with the functions below I can
present only one model instance at a time, whereas I''d like to present
several different model instances with each call.
from application.js...
function add_fields(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp("new_" + association, "g")
$(link).up().insert({
after: content.replace(regexp, new_id)
});
}
from application_helper.rb...
def link_to_add_fields(name, f, association)
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)
end
link_to_function(name, h("add_fields(this,
\"#{association}\",
\"#{escape_javascript(fields)}\")"))
end
What I think I need to do is figure out how to append to some
arbitrary place on the DOM, like the passed-in link element. I just
don''t know how.
Thanks for any help,
Grary
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.