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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:58:33+00:00 2026-05-19T00:58:33+00:00

I’m looking for a way to parse a text to turn into links the

  • 0

I’m looking for a way to parse a text to turn into links the entities of my web app contained within the text. To make it clear, let’s take this text as example:

Stoner rock and stoner metal are two related sub-genres of hard rock and heavy metal respectively, both combining elements of psychedelic rock, blues-rock, traditional heavy metal and doom metal. The genre emerged during the early 1990s and was pioneered foremost by the Californian bands Kyuss and Sleep.

I’d like to link all the genres, bands and albums that appear on the text (and exist as entities on my web app), like this:

<a href="/genre/1">Stoner rock</a> and stoner metal are two related sub-genres of hard rock and <a href="/genre/2">heavy metal</a> respectively, both combining elements of psychedelic rock, blues-rock, traditional <a href="/genre/2">heavy metal</a> and <a href="/genre/4">doom metal</a>. The genre emerged during the early 1990s and was pioneered foremost by the Californian bands <a href="/band/1">Kyuss</a> and <a href="/band/2">Sleep</a>.

I’ve thought different alternatives, such as:

  1. Storing rails code in the database which would output the links (Ugly and insecure),
  2. Do a full search on the database before inserting the text and
    a. Find and transform all my entities into links before saving or
    b. Store the entities ids on a separated column, place anchor tags and then on the view, combine each entity id with its anchor tag

I’m not really happy with any of the alternatives, I think should be a smarter way to handle this. Can you suggest a better approach? I’m using Ruby On Rails 3.

  • 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-19T00:58:33+00:00Added an answer on May 19, 2026 at 12:58 am

    Pseudo-Codes:

    Keywords.find_each do |keyword|
      text.gsub!(keyword, link_to keyword, some_path_for(keyword))
    end
    

    Depending on how many keywords you have, this task may be quite CPU intensive. Consider storing the text to DB first and have a background worker (like Resque or Delayed::Job) process each test.

    Show the original (unlinked) text until it has been processed. I would suggest using two different table fields for the unlinked and linked texts.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
i want to parse a xhtml file and display in UITableView. what is 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.