Constantizable, for constant tables

Reading time ~1 minute

It all started with a project in which I was working on, it contained too many constant tables like Country, City etc. It was a team of 3 people including me. We had tough time querying to check if the user belonged to a certain country.

if user.country.name == "India"
  # Some logic
else
  # Some logic
end

The above code was present all over the place. Being obsessed with elegance, we all wanted something like the following,

if user.country.india?
  # Some logic
else
  # Some logic
end

Additionally, there were many places in which we had to query for the country record.

  Country.find_by_name("United States of America")

And again we felt something wrong and wanted it to be more elegant and easy to read, so we decided we wanted to replace it with this,

  Country.united_states_of_america

We wrote a module to be included in all the constant model’s and being open source enthusiasts we extracted it into a gem which is hosted in github.

This module is young, so we need support from people to make it better. So feel free to contribute to the repo.

Introducing ember-cli-lunr

I was working on client side searching in an ember application. The requirements was very simple, consider the following array of strings...… Continue reading

How to change the hash_secret of Paperclip

Published on November 09, 2015

Clear your messed up rails console

Published on August 30, 2013