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 7566189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:20:58+00:00 2026-05-30T14:20:58+00:00

Made a comment system that shows/hides by a JS file but at the same

  • 0

Made a comment system that shows/hides by a JS file but at the same time this comment system is controlled by the same button that is used as a view counter. Both are run by two different Ajax files but both won’t work without the other one not working. Any help will be much appreciated! Thank you!

EDIT the HTML isn’t using @micropost and using micropost because @micropost is defined in a different partial. For those who are familiar to Michael Hartl’s Rails Tutorial, I have done this micropost with his code and teachings. I know this is screwing up everything for the ajax which is bringing back a @micropost rather than micropost but it won’t let me not put a @ in the ajax file so I am lost

Comment Button HTML

<span class='count-<%= micropost.id%>'>
<a href="/microposts/<%=micropost.id %>/upview" data-remote='true' class='CommentTitle' data-micropost='<%= micropost.id %>'>Comments</a>
</span>

Comment Ajax for changing counter

$("#count-<%=@micropost.id%>").html('<%="#{@micropost.view_count}"%>');
$(".count-<%=@micropost.id%>").html('<a href="/microposts/<%=@micropost.id%>/upview" data-remote="true" class="CommentTitle" data-micropost="<%= @micropost.id %>">Comments</a>');

Comment Button Slide Toggle JS

$(".CommentTitle").click(function(){
var title = this;
var postID = $(this).data('micropost');
$("#CommentContainer-" + postID).slideToggle("slow", function(){ 
$(".CommentTitle", title).html($(this).is(":hidden") ? "Comments" : "Comments");  
}); 
});
  • 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-05-30T14:20:59+00:00Added an answer on May 30, 2026 at 2:20 pm

    Assumption: When the user clicks on the link in the html, they’re sending a request to your upview action inside your MicropostsController.

    Inside that controller action method, you can assign an instance variable…

    @this_micropost = Micropost.find(params[:id]) # assuming you're RESTful, which it looks like
    

    then, inside your upview.js.erb, you can use that instance variable for whatever you want.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a commenting system that would comment under a micropost but the issue
While discussing a Java synchronization question , someone made a comment that the following
I ran across a comment that made me wonder: If you use a sharding
I have made a simple Rails application that allows people to comment on posts.
I'm using this for my code, it outputs to the xml file perfectly, but
G'day, Inspired by a comment I made in my answer to this question on
I'm part-way through making a simple comments system with PHP. With every comment that
I just saw a comment of suggesting J# , and it made me wonder...
Made this nice little loop for hiding and showing div's, works as a charm
I made a view to abstract columns of different tables and pre-filter and pre-sort

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.