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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:25:08+00:00 2026-05-16T11:25:08+00:00

I would like some suggestions on how to do this the best way: I

  • 0

I would like some suggestions on how to do this the best way:

I have a Rails application that handles comments. Each comment belongs to a context, such as a forum topic, or an image. The context reference is polymorphic.

I have partial that displays the comment, and that partial also holds links to edit or delete it for example. The links are generated using “edit_comment_path(the_comment)” and “comment_path(the_comment)”, etc.

Now, what I would like is to include the context in those links: instead of a link to “/comments/38” i would like them to link to “/images/5/comments/38” and “/topics/3/comments/63” …

The comments are only nested in one level, so there will never be a “/forums/18/topics/17/comments/74” link for example.

The application should have enough information to generate those links. But what is the best way to do that?

  • 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-16T11:25:08+00:00Added an answer on May 16, 2026 at 11:25 am

    I think what you’re looking for is the polymorphic_path helper. Assuming that you have an instance of the correct association in the view, you can create the paths like the following examples:

    edit_polymorphic_path([@image, the_comment]) # => /images/5/comments/38/edit
    
    polymorphic_path([@topic, the_comment]) # => /topics/3/comments/63
    

    These specs can be nested arbitrarily deep. See here for more.

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

Sidebar

Related Questions

I would like to find the best way to parse an UML Diagram that
I need some asp.net pagination code samples. I would like suggestions on open source
I would like some sugestion on how to design a table that gets like
I would like some help about an Android Application. I used the new Google
I would like some container that I can very efficiently append a variable amount
I would like some advice on the best approach to use in the following
I would like some of my preferences to have icons, like the Settings app.
I have a block of HTML that I would like to use as the
I have some code available in some form of AST and I would like
Looking for suggestions on how to best track this project structure in some 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.