I find the Rails online documentation at "http://guides.rubyonrails.org/form_helpers.html#dealing-with-ajax" difficult to follow, due to the way the information is organized. For example, I wanted to look for Ajax, so I looked under "View". But, because the material is organized in the MVC format, I can always see half of the solution, and not an entire one. I don''t know if anyone experienced the same thing. Back to Ajax, under View, I can see how the form is formed. But, what is missing is what happened after the form is submitted. Ajax is about interacting between client side and server side. I realized that I had to look under "Controller" for the other half of the solution, especially how Rails renders the result before going back to the client side. Long story short, here I have a simple form: <% form_tag({:controller => "main", :action => "contact"}, :remote => true, :update => "result") do %> Name:<br/><%= text_field_tag(:name, :"", :id => "name") %><br/><br/> Message:<br/><%= text_area_tag(:message, :"", :id => "message") %><br/> <%= submit_tag "Send" %> <% end %> <div id="result"></div> First problem, my form now disappeared. It appeared when it was <%= form_tag("/main/contact", :method => "post", :id => "contactForm") do %> What''s wrong with the above code ? Actually, what I really wanted to ask is more on the server side for this code to work: def contact ... end Anyway, one problem at a time. Thanks so much. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0689aefa55a2daa6b2c0c385818b3995%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
2013/5/30 Tommy Ng <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> > <% form_tag({:controller => "main", :action => "contact"}, :remote => >There should be an equal sign (=) just after the percent to tell erb, that it should output something> true, :update => "result") do %> > Name:<br/><%= text_field_tag(:name, :"", :id => "name") %><br/><br/> > Message:<br/><%= text_area_tag(:message, :"", :id => "message") > %><br/> > <%= submit_tag "Send" %> > <% end %> > <div id="result"></div> > > First problem, my form now disappeared. It appeared when it was<%= form_tag("/main/contact", :method => "post", :id => "contactForm")> do %> >Here you have that equal sign, so erb knows to output the formtag, in the line without it, the returnvalue of form_tag is just ommited. Also there are some nice railscasts about Ajax and a blogpost wich kickstarted me a few weeks ago: http://www.alfajango.com/blog/rails-3-remote-links-and-forms/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CA%2BbCVssC%3DnoG7XaQLa%2B45ry6rPLN9dc9Czrvquj8q7bP2S4kkQ%40mail.gmail.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Thanks Norbert! I read the document you recommended and here''s my opinion: I found this document pretty good. However, there are a few things I''m not clear. Under the "Putting it all together" section, the author said "enough explanation, let''s create a remote form that loads some content into the page,..." but there was not any form at all. Down below, I saw the "View" section which is totally empty. Then I saw the "Controller" section which talked about view, namely the "_show.html.erb". I''m very confused! I think the Comment example that the author tried to present is pretty good. But it would have been better if he would begin with a form, then the rails.js, along with any additional javascript, and finally how Ajax result is rendered in the controller, and formatted into JSON. Anyway, for the past four days devoting to Ajax on Rails, I have not seen a complete working Ajax example from anywhere, so frustrated right now. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9ab3c9d18659dc697302a8a17959fcb3%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.