Sunday, 29 September 2013

Displaying clickable URL's in my users created comments in Rails

Displaying clickable URL's in my users created comments in Rails

I am fairly new to Rails and I am not 100% sure as to how I can implement
the following function. In my Rails app, my users can create posts and
comment on those posts, but how can I show clickable URLs if a user puts
not only text but also URL's in a comment that they create. Here is my
posts show.html.erb template.
<div class="page-header">
<h4>All Comments</h4>
</div>
<% @post.newest_comments.each do |comment| %>
<div class="comments">
<h5><%= comment.body %></h5>
<li>
<small class="muted">
posted by <%= link_to comment.creator.username %> <%=
time_ago_in_words(comment.created_at) + ' ago' %>
<% if logged_in? && (comment.creator == current_user) %> |
<%= link_to 'edit', edit_post_comment_path(@post, comment) %> |
<i class="icon-user icon"></i>
<% end %>
</small>
</li>
</div>
<% end %>

No comments:

Post a Comment