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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:56:44+00:00 2026-06-03T03:56:44+00:00

I am using bb-code in a Rails application for postings and comments. At the

  • 0

I am using bb-code in a Rails application for postings and comments. At the moment, I have the following to put a post’s content in a view:

<%= @post.content.bbcode_to_html.html_safe.gsub('<a', '<a rel="nofollow"') %>

What is the best way to convert the bb-code to html and add “nofollow” to all links?

Thanks!

  • 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-03T03:56:45+00:00Added an answer on June 3, 2026 at 3:56 am

    The bb-ruby gem you are using allows for using custom BBCode translations passed as parameters to the bbcode_to_html method. However, if you really want ALL links to contain the rel="nofollow", I think your best bet is going to be monkey patching them gem itself. Based on the BBRuby source, you want to do this:

    module BBRuby
      @@tags = @@tags.merge({
        'Link' => [
          /\[url=(.*?)\](.*?)\[\/url\]/mi,
          '<a href="\1" rel="nofollow">\2</a>',
          'Hyperlink to somewhere else',
          'Maybe try looking on [url=http://google.com]Google[/url]?',
          :link],
        'Link (Implied)' => [
          /\[url\](.*?)\[\/url\]/mi,
          '<a href="\1" rel="nofollow">\1</a>',
          'Hyperlink (implied)',
          "Maybe try looking on [url]http://google.com[/url]",
          :link],
        'Link (Automatic)' => [
          /(\A|\s)((https?:\/\/|www\.)[^\s<]+)/,
          ' <a href="\2" rel="nofollow">\2</a>',
          'Hyperlink (automatic)',
          'Maybe try looking on http://www.google.com',
          :link]
        })
    end
    

    This will rewrite the BBRuby translator to always include a nofollow attribute. I would put this in config/initializers with a descriptive filename such as bbruby_nofollow_monkeypatch.rb

    As for the html_safe, I would leave that as is. As I understand it that is a preferred way of doing it and in my opinion it keeps your intent clear. The above monkey patch makes the line in your view more readable:

    <%= @post.content.bbcode_to_html.html_safe %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following view code in my Ruby (1.9.3) on Rails (3.1) application
In a Rails application using prototype, I have the following (simplified) code in my
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
I have recently created a new rails 3 application, using the code that I
I'm using a flash notice in a Rails application, with the following code: flash[:notice]
I have the following code in my Rails 3 application. @clinical_healthplan_spend = Clinical.select(ClientKey as
Using the less-rails gem. Using the following code to mix two colours: @base: #ffdc52;
I am using the following gem in my rails application: http://github.com/fnando/post_commit I am trying
I am using jQuery ui in a rails application. I want to load content
I have created a simple API for a Rails application using token-based-authentication that supports

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.