Rails options_from_collection_for_select with custom attributes for each option

You probably already know that you can use options_from_collection_for_select helper method generate <option></option> from a collection. If you are unaware of it, you can check this api documentation.

It helped me greatly until I needed some custom attributes to each <option></option> which will be used by jQuery for doing some tasks in UI level. Custom attributes will help me by reducing server calls for getting those information. However, I did not find a way set custom attributes with the above helper method. So, I’ve made a basic version of my own (if you prefer, you can override the original method). Put the following method in your helper file (may be in application_helper.rb).

Continue reading →

Rendering will_paginate links nicely with Twitter Bootstrap

When I was working with Moviemates (my one dream pet project), I had to use will_paginate gem for pagination of the movie listings. As the UI are based on Twitter Bootstrap, the will_paginate links (generated by its view helpers) were looking very ugly. Please check the following screenshot to see how bad it was looking!

I had to google a while for a decent look of these links. I’ve found a very effective but easy fix written by  oparrish and shared here. For your conveniences, the gist is attached here:

Continue reading →