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

  • Home
  • SEARCH
  • 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 8538957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:14:49+00:00 2026-06-11T11:14:49+00:00

So i have a page with a like button under my comments and am

  • 0

So i have a page with a like button under my comments and am trying to work out how to do this without refreshing the whole page currently the code looks like this:

- if can? :like, comment
  = " · "
  - if likes.find_by_user_id(current_user.id).nil?
    = link_to "Like", like_comment_path(comment), method: :post
  - else
    = link_to "Unlike", unlike_comment_path(comment), method: :post
- if comment.user == current_user
  = " · "
  = link_to "Delete", comment_path(comment), method: :delete,
    :data => { :confirm => "Are you sure you want to delete this comment?" }
- if likes.count > 0
.comment-likes
  - likers = likes.map { |like| link_to(like.user_name, "#") }
  - if likers.length > 1
    - likers = likers.slice(0, likers.length - 1).join(", ").concat(" and " +                               likers.slice(-1))
  - else
    - likers = likers[0]
  = "Liked by #{likers}".html_safe

Changing the method for like and unlike :post to :update seemed to make a big difference is this function using ajax and :post not? If not then how would i go about making this into a ajax function.

Heres my comments_controller.rb stuff

def like
 comment_vote = resource.like current_user
 Event.comment_liked!(comment_vote)
 redirect_to discussion_url(resource.discussion)
end

def unlike
 resource.unlike current_user
 redirect_to discussion_url(resource.discussion)
end
  • 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-11T11:14:51+00:00Added an answer on June 11, 2026 at 11:14 am

    = link_to "Like", like_comment_path(comment), method: :post, remote: true

    Then in your likes_controller create action, respond_to format.js

    def create
      respond_to do |format|
        format.html { .. your liking code .. }
        format.js {.. your liking code .. }
      end
    end
    

    This will then invoke the create.js.erb in your view folder, and you can dynamically update your html from there

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

Sidebar

Related Questions

I am doing this in order to have Facebook like button in my page:
I have a button on an html page declared like so: <button type=submit name=action
I have a group of radio buttons on my page like this: ALL (x)
I have buttons on a page that look like: <p> <a href=view.php> <input type=button
So I have a page like this you look at. On top I have
I have page like this: <ul id=cards> <li id=card1> <div>...</div> <div id=panel1> <form>...</form> <ol
I have a simple web page which looks like this. When clicked on the
I have a like button that is loaded from ajax on to my page.
I have many photos on the page and I'd like to add like buttons
i have a page like: and i need to print to pdf ( or

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.