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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:31:32+00:00 2026-06-16T20:31:32+00:00

The problem is that all the into it buttons on the page have the

  • 0

The problem is that all the “into it” buttons on the page have the same id and all the “undo” have the same id thus clicking one offsets others. Also the buttons only toggle once. I’m very new to rails,CSS,ajax and I appreciate the help, thank you.
enter image description here

Micropost_Helper.rb

def toggle_like_button(micropost, user)
  if user.voted_for?(micropost)
    link_to "undo", like_micropost_path(micropost), :class => "btn btn-mini btn-primary", :id =>"unvote_form", :remote => true
  else
    link_to "Into it!", like_micropost_path(micropost), :class => "btn btn-mini btn-primary", :id =>"vote_form", :remote => true
  end
end

Micropost Controller

def like
  @micropost = Micropost.find(params[:id])
  if @micropost.user_id != @current_user
    if @current_user.voted_for?(@micropost)
      @current_user.unvote_for(@micropost)
      respond_to do |format|
        format.html { redirect_to :back }
        format.js
      end
    else
      @current_user.vote_for(@micropost)
      respond_to do |format|
        format.html { redirect_to :back }
        format.js
      end
    end
  end
end

VIEW/microposts/like.js.erb <– with this i can only click the button’s once, need help here as well

$("#vote_form").html("undo")
$("#unvote_form").html("Into it!")
  • 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-16T20:31:33+00:00Added an answer on June 16, 2026 at 8:31 pm

    You should append uniq id to each button like this:

    def toggle_like_button(micropost, user)
      if user.voted_for?(micropost)
        link_to "undo", like_micropost_path(micropost), :class => "btn btn-mini btn-primary", :id =>"unvote_form_#{micropost.id}", :remote => true
      else
        link_to "Into it!", like_micropost_path(micropost), :class => "btn btn-mini btn-primary", :id =>"vote_form_#{micropost.id}", :remote => true
      end
    end
    

    and then you can reference one button in your like.js.erb:

    $("#vote_form_<%=@micropost.id%>").html("undo")
    $("#unvote_form_<%= @micropost.id%>").html("Into it!")
    

    That way you will have valid html and your problem should be solved.

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

Sidebar

Related Questions

All, I ran into this problem where for a UITextField that has secureTextEntry=YES, I
I have a (big) problem that all of you that work with Webforms might
Seems to be a problem that many people have, but all the answers I
I have a page that loads a list of values into a listbox. The
I have mvc3 application here my problem is on same page i.e on Index.cshtml
I have multilpe comment forms on the same page that popup in modal boxes
Essentially, after compiling utility jars w/ ANT, I'm having the problem that all the
I'm trying to copy some text to xml file. The problem is that all
I am facing a design problem that I cannot figure out at all. I
The problem is that when I try doing multiple animations they all happen the

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.