< mockra >

Div Links - 24 Feb 2012


Here’s a quick overview of creating a Div in Ruby on Rails that acts as a link using JQuery. The coffeescript looks like this:

jQuery ->   $('div.link').click ->

  window.location = $(this).attr('url')

  return false

Any Div with the class “link” will now link to the URL set in the url attribute. Here’s an example with HAML:

.title.link{ url: "#{article_url( article )}" }

  = link_to article.title, article