Search code examples
javascriptruby-on-railsruby-on-rails-4ransack

In rails ransack gem, when using 'sort_link' how can we define an onClick?


How can we add an onClick attribute to sort_link?

<%= sort_link @search, :created_at, "Created At" %>

I even tried this solution : Rails 3.2 and Ransack - Is it possible to pass additional params in a sort_link? but it didn't work.

What I really need is to add an onClick: "return false;" to make sure the page doesn't scroll to the top every time I click this link.


Solution

  • Correct me if I'm wrong, but doesn't Ransack refresh the page (make a request to the server, replace the markup) which would cause the page to scroll to the top?

    I don't think this has anything to do with click handlers..