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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:26:51+00:00 2026-06-10T21:26:51+00:00

In my Rails 3.1 app, I have a text field for comments and I

  • 0

In my Rails 3.1 app, I have a text field for comments and I want to be able to allow people to include clickable links (instead of just the url showing as plain text), as well as having the text field recognize when a user had line breaks in their text field (without the user adding html). How can I do this?

This works for showing a link if a user puts the html for a href:
<%= simple_format(@user.description) %>

And this works for recognizing and displaying the line breaks from carriage returns in the text_field:
<%= h(@user.description).gsub(/\n/, '<br/>').html_safe %>

However, I haven’t figured out how to do both, together.

  • 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-10T21:26:53+00:00Added an answer on June 10, 2026 at 9:26 pm

    How about this?

    #Doesnt work in this case
    #<%= simple_format( h(@user.description).gsub(/\n/, '<br/>') ).html_safe %>
    

    EDIT:
    Seems like you need auto_link function to achieve this. Though it is removed from rails 3.1 it is available as a gem. So if you are using rails 3.1 or later you need to get this from a separate gem

    #in Gemfile
    gem "rails_autolink", "~> 1.0.9"
    #in application.rb
    require 'rails_autolink'
    
    #Run
    bundle install
    
    #now in you view use it like
    <%= h auto_link(simple_format(text)) %>
    

    auto_link not only converts urls but also email addresses in clickable link. Get the document here.

    Reference Links:

    • http://rubygems.org/gems/rails_autolink
    • http://apidock.com/rails/ActionView/Helpers/TextHelper/auto_link
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Rails 3 web app, I have a Twitter text field in one
I want to use mysql with a rails app (I have never used mysql
I have a form field in my Rails app with a placeholder. I'd like
In a Rails app, I want to allow users to send messages from one
Simple rails app: I have 2 models, user and intro [which is simply a
In my rails app I have user, school, and course models. I have set
In a Rails app I have Sales and Salespeople: class Sale < ActiveRecord::Base belongs_to
I am creating a rails app and have used this code in one of
I have rails app which are working perfectly in the local computer. But when
I'm using the Simpleform gem for my rails app and I have a form

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.