Currently when a user in my app creates a new job post they enter a URL that links to their job page on their website. I then want to use this to link out to their site.
It is stored in my DB asjob.job_url
and I have defined an object @link
in my controller to find the job and relevant URL.
I currently have the following code to loop through all jobs and provide links:
<section id="job-wrapper">
<% @jobs.each do |job| %>
<%= link_to @link.job_url do %>
<%= job.title %>
<%= job.location %>
<%= job.job_type %>
<%= job.salary %>
<%= job.company %>
<% end %>
<% end %>
</section>
The issue I am having is that without the URL containing http://
rails assumes that the link is internal and so produces a link like localhost:3000/www.google.com
.
Is there a way for me to ensure Rails only ever recognises the link as external in the instance? Alternatively could someone explain how I can add http://
to all links on creation unless the user has already stated it?
Thanks in advance for your help!