I am trying to get a comment system going for a page and I want to use ajax to replace the partial holding the comments. When I press submit my little indicator icon pops up and nothing happens, but if I refresh the page the comment is there. This is the code I have for the comment in my controller: def comment id = params[:id] user_id = params[:user_id] comment = params[:comment] arr = {:place_id => id, :user_id => user_id, :comment => comment, :time_added => Time.now} place_comment = PlaceComment.new(arr) place_comment.save bar = Bar.find_by_id(id) render :update do |page| page.replace_html ''comments'', :partial => ''_comments'', :object => bar end end My partial called comments.rhtml looks like this: <div id="comments_made"> <% if !@bar.place_comments.nil? %> <% for comments in @bar.place_comments %> <div style="border-bottom: 1px solid #6699CC;"> <table> <tr> <td><%= image_tag url_for_file_column(comments.user, "photo", "thumb") unless comments.user.photo.nil? %></td> <td><%= h comments.user.username %> said:</td> </tr> </table> <table> <tr> <td><%= h comments.comment %></td> </tr> </table> </div><br/> <% end %> <% end %> </div> And I have a div wrapping the partial where the id is called "comments", I can''t see what I am doing wrong. -- 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 -~----------~----~----~----~------~----~------~--~---
You don''t need the underscore when referencing a partial this way. Change: page.replace_html ''comments'', :partial => ''_comments'', :object => bar To this: page.replace_html ''comments'', :partial => ''comments'', :object => bar On Aug 15, 2:28 pm, Scott Pn <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am trying to get a comment system going for a page and I want to use > ajax to replace the partial holding the comments. When I press submit my > little indicator icon pops up and nothing happens, but if I refresh the > page the comment is there. > This is the code I have for the comment in my controller: > def comment > id = params[:id] > user_id = params[:user_id] > comment = params[:comment] > arr = {:place_id => id, :user_id => user_id, :comment => comment, > :time_added => Time.now} > place_comment = PlaceComment.new(arr) > place_comment.save > bar = Bar.find_by_id(id) > render :update do |page| > page.replace_html ''comments'', :partial => ''_comments'', :object => > bar > end > end > > My partial called comments.rhtml looks like this: > <div id="comments_made"> > <% if !...@bar.place_comments.nil? %> > <% for comments in @bar.place_comments %> > <div style="border-bottom: 1px solid #6699CC;"> > <table> > <tr> > <td><%= image_tag url_for_file_column(comments.user, "photo", > "thumb") unless comments.user.photo.nil? %></td> > <td><%= h comments.user.username %> said:</td> > </tr> > </table> > <table> > <tr> > <td><%= h comments.comment %></td> > </tr> > </table> > </div><br/> > <% end %> > <% end %> > </div> > > And I have a div wrapping the partial where the id is called "comments", > I can''t see what I am doing wrong. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Aaron Wally wrote:> You don''t need the underscore when referencing a partial this way. > > Change: page.replace_html ''comments'', :partial => > ''_comments'', :object => bar > > To this: page.replace_html ''comments'', :partial => > ''comments'', :object => barThat didn''t work, and I thought you did have to use the underscore using rjs rendering (according to what I read in AWD) correct me if I''m wrong. -- 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 -~----------~----~----~----~------~----~------~--~---
I had this problem for awhile and it was because of the underscore. You might want to specify the controller when calling that partial and see if that works. :partial => ''controllerName/comments'' On Aug 15, 3:19 pm, Scott Pn <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Aaron Wally wrote: > > You don''t need the underscore when referencing a partial this way. > > > Change: page.replace_html ''comments'', :partial => > > ''_comments'', :object => bar > > > To this: page.replace_html ''comments'', :partial => > > ''comments'', :object => bar > > That didn''t work, and I thought you did have to use the underscore using > rjs rendering (according to what I read in AWD) correct me if I''m wrong. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Ok I finally got it, the problem was that I was passing in a bar object to the partial in the ajax updater controller method and the partial had no clue what to do with it, so I simply had to pass it an @bar instead of bar object and viola working fine now. 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 -~----------~----~----~----~------~----~------~--~---