How can I use ajax to add nested attributes dynamically into the form of an object? I followed the railscast : http://railscasts.com/episodes/74-complex-forms-part-2 but I''d like to use Ajax instead because the method above is sort of ugly. -- 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.
On 6 July 2010 17:33, Mlle <emstolfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How can I use ajax to add nested attributes dynamically into the form > of an object? > > I followed the railscast : http://railscasts.com/episodes/74-complex-forms-part-2 > > but I''d like to use Ajax instead because the method above is sort of > ugly.Have you seen http://railscasts.com/episodes/196-nested-model-form-part-1 and part 2? It does not use ajax but I would not describe it as ugly. Colin -- 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.
yes I''m currently using those last railscasts methods but it''s
getting
pretty difficult to use the method in the edit form.
I am trying to follow an ajax method that should insert a new nested
attirubte form upon clicking a submit button in a form_remote_for. I
put this in the create.rjs
association = :treatments
new_object @sample.class.reflect_on_association(association).klass.new
fields = :new_sample.fields_for(association, new_object, :child_index
=> "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f =>
builder)
end
page.insert_html :bottom, :sample, fields
but I don''t know how I can refer to the parent object''s form
in order
to call field_for. ":new_sample" doesn''t work. Any ideas?
On Jul 6, 6:36 pm, Colin Law
<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
wrote:> On 6 July 2010 17:33, Mlle
<emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > How can I use ajax to add nested attributes dynamically into the form
> > of an object?
>
> > I followed the railscast
:http://railscasts.com/episodes/74-complex-forms-part-2
>
> > but I''d like to use Ajax instead because the method above is
sort of
> > ugly.
>
> Have you seenhttp://railscasts.com/episodes/196-nested-model-form-part-1
> and part 2? It does not use ajax but I would not describe it as ugly.
>
> Colin
--
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@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Mlle wrote:> How can I use ajax to add nested attributes dynamically into the form > of an object? > > I followed the railscast : > http://railscasts.com/episodes/74-complex-forms-part-2 > > but I''d like to use Ajax instead because the method above is sort of > ugly.No, actually, you don''t want to use Ajax here. That will mean a round trip to the server each time you want to add a field. Bad idea. This should all be done on the client side. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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.