MariaDB + Ruby on Rails

Today we completed the Ruby on Rails official getting started guide blog example to demonstrate CRUD using Maria DB instead of the default sqlite3.

It ran smoothly and gave me the ability to use phpmyadmin to poke around my database. Some issues encountered were that, despite declaring relationships between tables on the model level, by default the database does not show any cascading or auto-delete.  It may well be something that was beyond the scope of a quick start tutorial, or the functionality may not exist at all.

Switching from Sqlite to MariaDB involved two steps:

In the Gemfile, comment out gem ‘sqlite3’ and add a line gem ‘mysql2’

[pastacode lang=”ruby” manual=”%23%20Use%20sqlite3%20as%20the%20database%20for%20Active%20Record%0A%23%20gem%20’sqlite3’%0Agem%20’mysql2′” message=”” highlight=”3″ provider=”manual”/]

In config/database.yml comment out the existing database connections and add this block (replacing it with your MariaDB credentials).

[pastacode lang=”ruby” manual=”development%3A%0A%20%20adapter%3A%20mysql2%0A%20%20encoding%3A%20utf8%0A%20%20database%3A%20yourDatabaseName%0A%20%20pool%3A%205%0A%20%20username%3A%20yourDatabaseUsername%0A%20%20password%3A%20yourDatabasePassword%0A” message=”” highlight=”” provider=”manual”/]

Of course this is only working in the dev environment but you’d only need to define it for production in the same file by replacing development: with production:

Exploring Ruby on Rails

Ruby on Rails is my latest adventure. At this point, after doing a basic blog tutorial to demonstrate CRUD, it seems like a solid framework. It preempts developer error by not allowing much freedom in how you go about things.

The error messages are full of information and allow a full stack trace or segmented. There are lots of command line shortcuts for instantiating MVCs for any component.

What really impresses me the most is how they’ve abstracted the database layer. It seems completely agnostic in terms of data storage. If you want sqlite3 (default) then leave it alone, MySQL setup involved changing one line in the Gemfile (config) and replacing the database.yml with the credentials for MySQL.

I’ve heard recently that the buzz for RoR is starting to fade but I feel that it is a great thing to have in my toolkit. The speed of development, once you get your head around the MVC, is blazingly fast.