Search code examples
javascriptjqueryruby-on-railsruby-on-rails-3ujs

Rails 3 UJS - on hover, not on click


For my show action, I render show.js.erb. This happens when I click a link_to set up with a :remote => true option. How can I set it up so this is triggered on hover?


Solution

  • Create a link with an attribute that won't trigger the Rails-UJS driver:

    <%= link_to 'mouse over me!', '#', :'data-remote-on-hover' => true %>
    

    and then wireup your own event:

    $('a[data-remote-on-hover]').hover(function() {
      // do something
    })