I have a rails app where users can post links inside a pin model. Here is the code to explain:
app/views/pins/_form.html.erb:
<%= f.text_field :website, placeholder: "http://wwww.website.com" %>
And in my views:
<% if @pin.website.blank? %>
<% else %>
<a href="<%= @pin.website %>" target="_blank">
<% end %>
It is working well if the users put the complete url (http://www.website.com) in the field, but if he forgets to add the 'http://' => (www.website.com) the page is obviously broken.
I was thinking to use the gem auto_link but I am a little bit confused on how to use it. Here is my config:
gemfile.rb
gem 'rails_autolink', '~> 1.1', '>= 1.1.6'
views:
<% if @pin.website.blank? %>
<% else %>
<%= auto_link(@pin.website) %>
<% end %>
application.rb
require 'rails_autolink'
But it just doesn't work, the link appears as plain text. Any help, what am I missing. I have been looking on other thread, but nothing seems to resolve my issue...
UPDATE: It is working well now if user passes the url just with the www. and without the http://, but is there a way to transform a raw text like this: website.com to http://www.website.com?