ruby on rails - URL replacement from submitted comment -
i displaying users website url in comments. works correctly on view page, wondering if can change how url displayed.
can display http://google.com website? or remove http, https , display google.com?
here current code:
<%= link_to comment.website, url_for(comment.website), target: '_blank' %>
if comment.website
returns string as: "http://google.com" can use regex trim "//" using:
comment.website.remove(/.*\/\//)
this crash if comment.website
nil can use different syntax write same code
comment.website.try(:remove, /.*\/\//)
so:
<%= link_to comment.website.try(:remove, /.*\/\//), url_for(comment.website), target: '_blank' %>
go , check http://rubular.com/r/ufmy2djohw play regex
Comments
Post a Comment