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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:15:37+00:00 2026-05-18T08:15:37+00:00

Rails has a few built in helper methods for dealing with links (url_for, link_to,

  • 0

Rails has a few built in helper methods for dealing with links (url_for, link_to, auto_link), but none do exactly what I need:

I want the user to be able to specify a URL, and for me to be able to alter the text it appears as. auto_link almost does what I want, except you can’t change the link text, and it doesn’t recognize links that are typed in like: stackoverflow.com. You have to enter http://www.stackoverflow.com

I want the user to be able to enter something like “stackoverflow.com”, and for me to be able to generate html like this:

<a href="http://www.stackoverflow.com">Username</a>

Is there a plugin out there that adds additional link helper methods?

  • 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-18T08:15:38+00:00Added an answer on May 18, 2026 at 8:15 am

    You can pass a block to auto_link, and the result of that will be the link text. For example:

    <% str = "something like http://stackoverflow.com would be the input" %>
    <%= auto_link(str) do |url|
          "Username"
        end
    %>
    

    generates this HTML:

    something like <a href="http://stackoverflow.com">Username</a> would be the input
    

    And if you wanted the link text to be different depending on what the URL was, you could do something like:

    <% str = "something like http://stackoverflow.com, and another http://stackexchange.com url" %>
    <%= auto_link(str) do |url| 
      if url.match(/overflow/) 
        "Username"
      else
        "Something"
      end
    end %>
    

    which generates:

    something like <a href="http://stackoverflow.com">Username</a>, and another <a href="http://stackexchange.com">Something</a> url
    

    This plus the tips in the comments about adjusting the URL regex seem like they would do what you want.

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

Sidebar

Related Questions

I'm aware that Rails has a few different levels for logging, but how can
I'm diving into web development and I've built a few basic rails apps, but
Rails has the rest autho plugin which works well but is there a solution
I have a few data values that I need to store on my rails
I've got a few tests running with RSpec for a Rails site, but despite
I am using a few persisted Tire models in my Rails app. Searching has
God has helped us keep a few services running on a Rails box (Nginx
My rails app has a simple model Links which tracks all the Urls associated
I have a Ruby on Rails model that has quite a few HABTM relationships.
Rails has a nice idiom that makes it easy for you to 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.