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

The Archive Base Latest Questions

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

Problem: Looking for the right comment that belongs to a post I am trying

  • 0

Problem: Looking for the right comment that belongs to a post

I am trying to implement a “like” function (just like on facebook) for comments on a specific post. I’ve already implemented the same function for my posts, but “pointing at the right comment” is giving me hard time. To clarify, my “like” function results in the following GET call:

http://localhost:3000/posts/11/comments/4/like

But it’s actually supposed to call

/posts/4/comments/11/like

I checked my route, and it seems right to me

like_post_comment GET    /posts/:post_id/comments/:id/like(.:format)

So I guess the problem lies in the controller.

In the beginning of my like action in comments_controller, I have

def like
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:comment])

I think this must be wrong, but I’m not sure why or how to fix it. The other actions set local variables @post and @comment in a similar way, but they do the job correctly.

def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(params[:comment])

def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:comment])

How I render my link to comment

<td><b><%= link_to 'like', like_post_comment_path(comment) %></b></td>
  • 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-14T17:11:57+00:00Added an answer on June 14, 2026 at 5:11 pm

    Replace your link from

    <td><b><%= link_to 'like', like_post_comment_path(comment) %></b></td>
    

    to

    <td><b><%= link_to 'like', like_post_comment_path(@post, comment) %></b></td>
    

    And replace your like action in controller with

    def like
      @post = Post.find(params[:post_id])
      @comment = @post.comments.find(params[:id])
      # ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hej everyone, problem : I am looking for right way to convert an index
Thanks for looking on this problem. I have a page that is totally valid
My problem is that I was looking for way to use both storyboard and
Have an interesting problem and am looking for the right solution. We have around
I'm looking for the right way to fix a problem with an array in
Is there a better solution to the problem of looking up multiple known IDs
Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning
Problem Hey folks. I'm looking for some advice on python performance. Some background on
I am looking for a simple answer for this problem... I have a UITextView
I'm looking for the generally accepted/best solution to this problem. Problem I have a

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.