Rails 3 Select Tag with List of Countries

This post is to assist to create a select tag in a view (HTML) with a list of countries.

The solution presented here:

– The countries are stored in a table in database. If you don’t want to have a table with countries in DB, you can easily modify the code below to have countries as an array in code.

– Helper to show a list of countries in select tag in HTML

 

You can find the whole solution on github.

Continue reading

How to pass multiple attributes to find_or_create_by in Rails 3 : the Ruby way

Ruby and Rails have many magic features like blocks/closures, duck typing/mix-ins/modules,  method_missing, poetry mode.

One of the common tasks in programming web applications on Rails is finding a row in a table by several columns and creating a new row in case of row is missing.

Continue reading