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

Installing mysql2 gem on Ruby 1.9.2 and Rails 3.0.5 on Windows

When running ‘rake db:create’, you may get the following error:

>rake db:create
rake aborted!
126: The specified module could not be found. - d:/RailsInstaller/Ruby1.9.2/li

or may get these errors while installing mysql:

rake aborted !
uninitialized constant mysql2

Error ‘uninitialized constant mysql2’ comes when mysql2 installation is not done properly.

Continue reading