Satya's blog - Ruby on Rails auto_link bug

May 09 2009 11:44 Ruby on Rails auto_link bug

In Ruby on Rails, the auto_link helper takes a string and automatically links URLs and email addresses in the string, producing output suitable for a web page. Today we had a URL that ended in a query string, with a slash in the string, like so: .../end?tag=/mom

auto_link wouldn't recognize the slash as part of the link and ended the link at the "tag=" part. After some googling, I located action_view/helpers/text_helper.rb and added the slash before the dash in the regexp for the query string. This is in a constant called AUTO_LINK_RE.

Update: Swivel blog has a better way to fix this, with an initializer.

Last updated: Jun 04 2009 15:58

Tag: rails geeky

Comments:
  • Thu Jun 4 14:07:13 2009 ben wrote:
    Thanks for the tip -- I implemented the workaround in core_ext.rb and wrote it up on the Swivel code blog.
  • Thu Jun 4 15:57:39 2009 Satya wrote:
    Thanks! I should do the initializer thing too, rather than edit the Rails core code.