Hi there(i''m new to rails, so please be patient =D), i''m facing some problems with forms and ajax =/ hope someone can help me, because i was searching here and on the api docs, but no luck then I believe that i''m missing something... I have a form_remote_for, and i want it to submit my form in a ajax request. Ok! but the page is still refreshing when i make the submit... how do i make the submit the right way? i don''t think i''m doing it right using ''p.submit'' So, if someone can explain to me how to do this, or lead me at the right way Thanks, Andreh //new.html.erb <% javascript_include_tag(:all) %> <div id="posts"> <% for posts in @user.posts %> <%= posts.description %> <br /> <% end %> </div> <% form_remote_for :post, @post, :url => { :action => ''create'' } do |p| %> Post:<br /> <%= p.text_area :description %> <%= p.submit ''Post!'' %> <% end %> // the controller def create @user = User.find_by_name(params[:name]) @user.posts << Post.new(params[:post]) respond_to do |format| if (@user.save) flash[:notice] = "ok!" format.html { render :action => ''show'' } else format.html end end end -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Use <%= submit_tag "Post!" %> On Jan 24, 2008 9:52 AM, Andreh Luis <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi there(i''m new to rails, so please be patient =D), > > > i''m facing some problems with forms and ajax =/ hope someone can help > me, because i was searching here and on the api docs, but no luck then > > I believe that i''m missing something... > > I have a form_remote_for, and i want it to submit my form in a ajax > request. > Ok! > > but the page is still refreshing when i make the submit... > > how do i make the submit the right way? i don''t think i''m doing it right > using ''p.submit'' > > So, if someone can explain to me how to do this, or lead me at the right > way > > Thanks, > > Andreh > > > //new.html.erb > > <% javascript_include_tag(:all) %> > > <div id="posts"> > <% for posts in @user.posts %> > > <%= posts.description %> <br /> > <% end %> > </div> > > > <% form_remote_for :post, @post, :url => { :action => ''create'' } do > |p| %> > Post:<br /> > <%= p.text_area :description %> > <%= p.submit ''Post!'' %> > <% end %> > > // the controller > def create > @user = User.find_by_name(params[:name]) > @user.posts << Post.new(params[:post]) > respond_to do |format| > if (@user.save) > flash[:notice] = "ok!" > format.html { render :action => ''show'' } > else > format.html > > end > end > end > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
looks like the same with submit_tag the page stills do a refresh... like it is without ajax Thanks! Ryan Bigg wrote:> Use <%= submit_tag "Post!" %> > > On Jan 24, 2008 9:52 AM, Andreh Luis <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> request. >> Thanks, >> >> <% end %> >> format.html >> >> end >> end >> end >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Ryan Bigg > http://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Have you tried debugging the page with Firebug? It almost sounds to me like you would want to take a look a the network calls and make sure you are getting all of the JS files. Just my 2c JW On Jan 23, 6:43 pm, Andreh Luis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> looks like the same with submit_tag > the page stills do a refresh... > like it is without ajax > > Thanks! > > > > Ryan Bigg wrote: > > Use <%= submit_tag "Post!" %> > > > On Jan 24, 2008 9:52 AM, Andreh Luis <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > >> request. > >> Thanks, > > >> <% end %> > >> format.html > > >> end > >> end > >> end > >> -- > >> Posted viahttp://www.ruby-forum.com/. > > > -- > > Ryan Bigg > >http://www.frozenplague.net > > Feel free to add me to MSN and/or GTalk as this email. > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ops! i figured it out! when i saw on firebug that i was getting no js calls i went to look at my javascript_include_tag, i just saw that i missed the ''='' on the <% .. beginners mistake.. sorry.. and thanks for the help about how to submit the form! -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, another thing, now my page looks like the following: But, i don''t know why, the form_remote_for block, is being duplicated everytime i click on submit_tag, and the post_wall div isn''t being updated =/ there is form_remote_for just like mine on the Rails Way book... so i don''t know why it doesn''t get updated! and duplicates teh post for... Thanks for the patience again! <div id="form_post"> <% form_remote_for :post, @post, :update => ''post_wall'', :url => { :action => ''create'' } do |p| %> Post:<br /> <%= p.text_area :description %> <%= submit_tag ''Post!'' %> <% end %> </div> <div id="post_wall"> <% for posts in @user.posts.reverse %> <%= posts.description %> <br /> <% end %> </div> -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Don''t know what to tell ya, I am looking over the snippet of code and nothing is popping out as far I can see. Check the DOM and see if the flow is correct. could be as simple as a missing "/" or missing closing tag for a div. JW On Jan 23, 2008 8:06 PM, Andreh Luis <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, another thing, now my page looks like the following: > > But, i don''t know why, the form_remote_for block, is being duplicated > everytime i click on submit_tag, and the post_wall div isn''t being > updated =/ > there is form_remote_for just like mine on the Rails Way book... so i > don''t know why it doesn''t get updated! and duplicates teh post for... > > Thanks for the patience again! > > > <div id="form_post"> > > <% form_remote_for :post, @post, :update => ''post_wall'', :url => { > :action => ''create'' } do |p| %> > Post:<br /> > <%= p.text_area :description %> > <%= submit_tag ''Post!'' %> > <% end %> > </div> > <div id="post_wall"> > <% for posts in @user.posts.reverse %> > <%= posts.description %> <br /> > <% end %> > </div> > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Are you sending the form back in the ajax request? I think this might be what you''re doing, because you''re updating the div post_wall (which is inside the form) which will keep putting the form back in there. On Jan 24, 2008 11:46 AM, Jason West <jlwestsr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Don''t know what to tell ya, I am looking over the snippet of code and > nothing is popping out as far I can see. > > Check the DOM and see if the flow is correct. could be as simple as a > missing "/" or missing closing tag for a div. > > JW > > > On Jan 23, 2008 8:06 PM, Andreh Luis <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > > > Hi, another thing, now my page looks like the following: > > > > But, i don''t know why, the form_remote_for block, is being duplicated > > everytime i click on submit_tag, and the post_wall div isn''t being > > updated =/ > > there is form_remote_for just like mine on the Rails Way book... so i > > don''t know why it doesn''t get updated! and duplicates teh post for... > > > > Thanks for the patience again! > > > > > > <div id="form_post"> > > > > <% form_remote_for :post, @post, :update => ''post_wall'', :url => { > > :action => ''create'' } do |p| %> > > Post:<br /> > > <%= p.text_area :description %> > > <%= submit_tag ''Post!'' %> > > <% end %> > > </div> > > <div id="post_wall"> > > <% for posts in @user.posts.reverse %> > > <%= posts.description %> <br /> > > <% end %> > > </div> > > -- > > Posted via http://www.ruby-forum.com/. > > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m doing this in my action: def create @user = User.find_by_name(params[:name]) @user.posts << Post.new(params[:post]) respond_to do |format| if (@user.save) flash[:notice] = "Post criado com sucesso" format.html { render :action => ''show'' } else format.html end end end I believe you''re correct, i''m sending the form back on the div, have any idea of what i could do? i''m kinda lost now.. Ryan Bigg wrote:> Are you sending the form back in the ajax request? I think this might be > what you''re doing, because you''re updating the div post_wall (which is > inside the form) which will keep putting the form back in there. >-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I''m still having trouble to solve this... anyway i don''t know how to use the respond_to without sending the form back for my div.. i saw an example just like this on the Rails Way book, but i couldn''t make it work... i just don''t know how to solve this... Thanks for the help, -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---