I have implemented some coffeescript that allows my table rows to be links.
The issue I am having however is that my app seems to be adding http.com// into the beginning of my Job URLs so instead of getting www.google.com I would get www.http.com//www.google.com
I have the current setup:
#Coffeescript
$ ->
$('tr[href]').click -> window.open 'http://' + $(this).attr('href');
#View
<% @jobs.each do |job| %>
<tr href='<%= job.job_url %>'>
<td><strong><%= job.title %></strong></td>
<td><%= job.company %></td>
<td><%= job.city %>, <%= job.country %></td>
</tr>
<% end %>
The URLs stored in my database all have www. as part of the URL but not http://.
Any advice on what might be going on here would be much appreciated. Thanks
job_urlreturns a complete url, e.g.whereas
job_pathreturns a relative path, e.g.If you are going to use
job_url, you should NOT append the protocol in your coffeescript, as your URLs will be horked because they will be appending the protocol twice.You might also consider, as a best practice, to use
data-hrefas the attribute on your<tr>. I try to do this, it makes the link between the HTML and the Javascript more explicit. I have spent many an hour tracking down bugs where the designer removed or renamed a class or attribute element that my Javascript was relying upon!So, in your ERB:
In the Coffeescript: