Search code examples
ruby-on-railsransack

Pass css classes to Ransack's sort_link


Working on a RoR project for myself (self-teaching), now toying with Ransack which is an awesome gem...

I would like to have a few "sort_links" on top of my index page - work as expected, but I can't figure out how to style these links. Have tried this but didn't work:

<%= sort_link(@q, :title), class: 'btn btn-info btn-small') %>

The wiki and readme of ransack don't really talk about this?


Solution

  • There is a ransack option hash before the html options hash. You can take a look at this code if you want to see what the sort_link helper is doing.

    Ransack V3

    <%= sort_link(@q, :title, class: 'btn btn-info btn-small') %>
    

    +1 Luke pointed out you no longer need an empty hash, thanks!

    Ransack V1 & 2

    <%= sort_link(@q, :title, {}, class: 'btn btn-info btn-small') %>