How can I use ajax to add nested attributes dynamically into the form
of an object?
I followed the railscast :
but I’d like to use Ajax instead because the method above is sort of
ugly.
How can I use ajax to add nested attributes dynamically into the form
of an object?
I followed the railscast :
but I’d like to use Ajax instead because the method above is sort of
ugly.
On 6 July 2010 17:33, Mlle [email protected] wrote:
How can I use ajax to add nested attributes dynamically into the form
of an object?I followed the railscast : #74 Complex Forms Part 2 - RailsCasts
but I’d like to use Ajax instead because the method above is sort of
ugly.
Have you seen
and part 2? It does not use ajax but I would not describe it as ugly.
Colin
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?
Mlle wrote:
How can I use ajax to add nested attributes dynamically into the form
of an object?I followed the railscast :
#74 Complex Forms Part 2 - RailsCastsbut 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.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs