Hi all. I''m doing my own blog-like site, so I''ve an Post controller and an Comments controller and I want to ajaxify my comments form. So, I''ve did the following: [comments_controller.rb] class CommentsController < ResourceController::Base belongs_to :post, :article, :photo create do flash "Comment posted successfuly" wants.html { redirect_to :back } wants.js { render :layout => false } end end [/comments_controller.rb] [create.js.rjs] page.replace_html("comments", :partial => "comment", :collection => @post.comments) [/create.js.rjs] [views/posts/show.html.erb] <%= render :partial => "post", :object => @post %> <h3>Comments</h3> <div id="comments"> <%= render :partial => "comments/comment", :collection => @post.comments %> </div> <% remote_form_for([@post,Comment.new], :update => "new_comment") do |f| %> <%= render :partial => "comments/form", :locals => { :f => f } %> <p> <%= submit_tag "Create" %> </p> <% end %> [/views/posts/show.html.erb] Please, also note that I''m using resource_controller plugin. When I write down my comment, comments_partial is updated and my new comment appears, but I also got the following: [output] Element.update("comments", "\u003Ca href=\"http://presto.stellar.com.br\"\u003Edavi\u003C/a\u003E said, in Post Fouth post at\nSun Jun 15 12:04:33 -0300 2008:\u003Cbr/\u003E\nCommenting! I''m enjoying Rails!!! Finaly!! =D\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca href=\"http://presto.stellar.com.br\"\u003Edavi\u003C/a\u003E said, in Post Fouth post at\nSun Jun 15 12:05:25 -0300 2008:\u003Cbr/\u003E\nI''ve learned how to restart Passenger... =)\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca href=\"http://my.coolsite.com\"\u003Eauthor\u003C/a\u003E said, in Post Fouth post at\nMon Jun 16 00:50:43 -0300 2008:\u003Cbr/\u003E\nmy comment\n\u003Cbr/\u003E\u003Cbr/\u003E"); [/output] and my comments'' form desapair. What am I missing here? Please, sorry for my very bad English. Best regards, -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal YIM : davi_vidal ICQ : 138815296 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jun 16, 4:56 am, Davi Vidal <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> [output] > Element.update("comments", "\u003Ca > href=\"http://presto.stellar.com.br\"\u003Edavi\u003C/a\u003E said, in Post > Fouth post at\nSun Jun 15 12:04:33 -0300 2008:\u003Cbr/\u003E\nCommenting! > I''m enjoying Rails!!! Finaly!! =D\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca > href=\"http://presto.stellar.com.br\"\u003Edavi\u003C/a\u003E said, in Post > Fouth post at\nSun Jun 15 12:05:25 -0300 2008:\u003Cbr/\u003E\nI''ve learned > how to restart Passenger... =)\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca > href=\"http://my.coolsite.com\"\u003Eauthor\u003C/a\u003E said, in Post Fouth > post at\nMon Jun 16 00:50:43 -0300 2008:\u003Cbr/\u003E\nmy > comment\n\u003Cbr/\u003E\u003Cbr/\u003E"); > [/output]Is that what is inserted into your comments div? The thing here is that ajax in rails can be used in one of two ways. The first is that you give remote_form_for, link_to_remote etc... a dom id via the :update option and then response from your action replaces the contents of that page element. In this case you action should just render an html fragment. The second way is your action renders javascript, and the javascript on the page executes it when it comes back (rjs is one way of generating javascript. Here you''re mixing the two: you''re specifying :update but then you''re rendering rjs. Pick one or the other. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Em Monday 16 June 2008, Frederick Cheung escreveu:> On Jun 16, 4:56 am, Davi Vidal <davivi...-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote: > > [output] > > Element.update("comments", "\u003Ca > > href=\"http://presto.stellar.com.br\"\u003Edavi\u003C/a\u003E said, in > > Post Fouth post at\nSun Jun 15 12:04:33 -0300 > > 2008:\u003Cbr/\u003E\nCommenting! I''m enjoying Rails!!! Finaly!! > > =D\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca > > href=\"http://presto.stellar.com.br\"\u003Edavi\u003C/a\u003E said, in > > Post Fouth post at\nSun Jun 15 12:05:25 -0300 2008:\u003Cbr/\u003E\nI''ve > > learned how to restart Passenger... > > =)\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca > > href=\"http://my.coolsite.com\"\u003Eauthor\u003C/a\u003E said, in Post > > Fouth post at\nMon Jun 16 00:50:43 -0300 2008:\u003Cbr/\u003E\nmy > > comment\n\u003Cbr/\u003E\u003Cbr/\u003E"); > > [/output] > > Is that what is inserted into your comments div?Yes.> The thing here is that ajax in rails can be used in one of two ways. > The first is that you give remote_form_for, link_to_remote etc... > a dom id via the :update option and then response from your action > replaces the contents of that page element. In this case you action > should just render an html fragment. The second way is your action > renders javascript, and the javascript on the page executes it when > it comes back (rjs is one way of generating javascript. Here you''re > mixing the two: you''re specifying :update but then you''re rendering > rjs. Pick one or the other. >I''ve droped down :update and all is working fine now. Thank you very much, Fred. -- Davi Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal YIM : davi_vidal ICQ : 138815296 --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---