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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:22:23+00:00 2026-06-17T11:22:23+00:00

I have a post model that has many comments . Now a link to

  • 0

I have a post model that has many comments. Now a link to a comment is actually a url like so /post/1?page=3#26.

What I want to be able to do is call link_to "foobar", @comment and have it generate the correct url. I already know how to calculate the page a comment is on so you can assume @comment.page_num will return the correct integer.

I think this is going to require customizing the polymorphic_url somehow.

If it can’t easily be done maybe I need a helper function link_to_comment but I’d like it to be able to do everything link_to can, ie passing blocks and what not.

  • 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-17T11:22:25+00:00Added an answer on June 17, 2026 at 11:22 am

    So this is what I ended up doing. It pretty simple but does exactly what I need. My original scope might have been too ambitious. Classic case of keep it simple stupid.

    module CommentsHelper
    
      def comment_page_url(comment)
        post_url(comment.post, page: comment.page_num, anchor: comment.id)
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a post controller that has many comments. The post model has a
I have a post model that has many tags through taggings. let's say: @posts
I have a model User that has defined in user.rb many relationships like has_many
I have a Topic model and a Post model. A Topic has many Posts,
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have 3 model, User, Post, Comment with definition like below class Post <
I have a model Post that has_many :comments . The form that will post
I have a model that has counter_cache enabled for an association: class Post belongs_to
Suppose I have a Post model which has_many Comments. I want to get the
I have a Post model that has_many :comments . The question is: how can

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.