Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:15:40+00:00 2026-06-01T22:15:40+00:00

I want to get .comment_container for the post just made and place it after

  • 0

I want to get “.comment_container” for the post just made and place it after the last comment.

Each comment and it’s related content is stored in a “.comment_container” class.

The code below does what I need but not 100%. Rather than append the word TEST I want to append the new comment_contaner holding the comment just posted.

I’ve been cracking at this all day and this is how far I’ve come. I would appreciate some solutions with examples if possible.

JQuery:

$('#new_comment').on('ajax:success', function(){
  $(this).parent('.post_content').find('.comment_container:last').after("TEST");
});

<% sleep 1 %>

HTML:

       <div class="postHolder">
        <nav class="micropostOptions">
         <ul class="postMenu">
           <li class="deletePost"><%= link_to content_tag(:span, "Delete post"), m, :method => :delete, :confirm => "Are you sure?", :title => m.content, :class => "message_delete" %>
           </li>
           <li class="disableCommenting"><%= link_to content_tag(:span, "Pause commenting"), "2" %></li>
           <li class="blockCommenter"><%= link_to content_tag(:span, "Block commenter"), "3" %></li>
           <li class="openInNewWindow"><%= link_to content_tag(:span, "Open in new window"), "4" %></li>
           <li class="reportAbuse"><%= link_to content_tag(:span, "Report abuse"), "5" %></li>
         </ul>  
       </nav>


                <%= link_to image_tag(default_photo_for_current_user, :class => "poster_photo"), current_users_username %>







<div class="post_content">
    <div class="post_container">

                        <div class="userNameFontStyle"><%= link_to current_users_username.capitalize, current_users_username %> -
                        <div class="post_time"> <%= time_ago_in_words(m.created_at) %> ago.</div> </div>  
                  <%=  simple_format h(m.content) %> </div>

                        <% if m.comments.any? %>
                   <% comments(m.id).each do |comment| %>

                    <div class="comment_container">
                        <%= link_to image_tag(default_photo_for_commenter(comment), :class => "commenter_photo"), commenter(comment.user_id).username %>

                        <div class="commenter_content"> <div class="userNameFontStyle"><%= link_to commenter(comment.user_id).username.capitalize, commenter(comment.user_id).username %> - <%=  simple_format h(comment.content) %> </div>
                    </div><div class="comment_post_time"> <%= time_ago_in_words(comment.created_at) %> ago. </div>


                   </div>


                        <% end %>
                    <% end %>


                <% if logged_in? %>
                <%= form_for @comment, :remote => true, :html => {:class => "new_comment} do |f| %>
                <%= f.hidden_field :user_id, :value => current_user.id %>
                <%= f.hidden_field :micropost_id, :value => m.id %>
                <%= f.text_area :content, :placeholder => 'Post a comment...', :class => "comment_box", :rows => 0, :columns => 0 %>

        <div class="commentButtons">         
          <%= f.submit 'Post it', :class => "commentButton" %>
           <div class="cancelButton"> Cancel </div>
        </div>   
                <% end %>

                <% end %>
    </div>


</div>

Comments controller:

class CommentsController < ApplicationController

    def create

         @comment = Micropost.find(params[:comment][:micropost_id]).comments.build(params[:comment])
           respond_to do |format|
                 if @comment.save


                    unless params[:comment][:recipient].blank? # this will be blank when current user is commenting/replying on their own wall
                    recipient = User.find(params[:comment][:recipient])
                    UserMailer.new_wall_post_comment_notification(recipient, current_user).deliver if recipient.email_notification == 1 
                    end
                    format.js   { render :post_comment }
                    else
                    format.js   { render :form_errors }
                    end
           end
    end

end

Comment partial:

<div class="comment_container">

        <%= link_to image_tag(default_photo_for_commenter(@comment), :class => "commenter_photo"), commenter(@comment.user_id).username %>
     <div class="commenter_content"> 

        <div class="userNameFontStyle"><%= link_to commenter(@comment.user_id).username.capitalize, commenter(@comment.user_id).username %> - <%=  simple_format h(@comment.content) %> 
        </div>

    </div>

    <div class="comment_post_time"> 
        <%= time_ago_in_words(@comment.created_at) %> ago. 
    </div>

</div>

Seems to be working apart from 1 minor issue. Let’s say I post 4 comment… 1 after each other. First comment 1, second 2, third 3 and fourth 4.. e.g. 1, 2, 3 and 4 the result I get is this:

Posting 1, 2 , 3 4

I have a feeling it’s something to do with some kind of reset needing to be done after each comment is left. After refreshing the comments display as expected. 1, 2, 3 and 4. Any thoughts?

Kind regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:15:43+00:00Added an answer on June 1, 2026 at 10:15 pm

    You should make the partial for rendering your Comments (I guess it should be the /views/comments/_comment.html.erb).

    Then just replace:

    .after("TEST");
    

    with:

    .after("<%= j render @comment %>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want get all of the Geom objects that are related to a certain
I just want get a 2 dimension array of List in c#. In my
I want get the time used for a case so I can create an
I want get as much as possible from Redis + Hiredis + libevent. I'm
I want to get the top #nr_of_rows - (int)(#nr_of_rows / 10 - 1) of
I want to get myself into programming some serious GUI based applications, but when
I want to get print out invoice but also wanna set margins and page
I want to get an entity with its sub-properties. How can I do that
I want to get all values of a set interface in one go as
I want to get show information from myspace artists. One way I could do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.