Browse Source

Make URIs in text clickable

Frans Bergman 7 years ago
parent
commit
bd28538b06
2 changed files with 5 additions and 1 deletions
  1. 4 0
      app/helpers/application_helper.rb
  2. 1 1
      app/views/messages/_message.html.erb

+ 4 - 0
app/helpers/application_helper.rb

@@ -8,4 +8,8 @@ module ApplicationHelper
       page_title + " | " + base_title
     end
   end
+
+  def format_content(text)
+    simple_format(text).gsub(/([A-z]+:[^\s<]+)/, '<a href="\0">\0</a>').html_safe
+  end
 end

+ 1 - 1
app/views/messages/_message.html.erb

@@ -3,7 +3,7 @@
     <%= render message.user %>
   </div>
   <div class="panel-body">
-    <%= message.content %>
+    <%= format_content(message.content) %>
   </div>
   <div class="panel-footer">
     Posted at: <%= message.created_at %>