Ruby on Rails for a .NET Developer – Part 1
Looking at my blog or resume, you will immediately know that I am a .net developer and my entire programming career has been Microsoft-centric. I have been wanting to play with Ruby on Rails due to its inescapable popularity and I was actually surprised to learn that the language itself (Ruby) was developed in the early 90’s… So it’s not really new. Ruby on Rails is a framework that sits on top of it…
NOTE: forgive me if any of this is wrong, my RoR experience as of right now is 35 minutes…
Anyway, this post is not about the history of Ruby or a comparative analysis of which language or platform is better… It is just a part of a series of blog posts that I will be writing as I learn more about RoR. Everything is written from my perspective i.e. a 100% windows user and a .net developer. So I am in foreign lands here.
The Setup
My current setup is a Mac Mini running Leopard with
The Environment
So after downloading all the RoR stuff from this website, I followed the steps and managed to create an empty application like this:
- Open a terminal window
- Run rails /users/emad/code/favewares
- Run cd path/to/your/new/application
- Run ruby script/server
Then I opened http://localhost:3000 in my browser and got to the welcome page shown below.
Time to create the database, so I had to go download MySQL and install it which was surprisingly very straight forward:
- Double click the MySQL installer
- Double click the MySQL Startup Item installer
Then I ran into problems trying to get things going and quickly realized that being a windows user, I needed a GUI tool. So I downloaded one from the MySQL website and installed it which was also pretty straight forward. Until I tried to connect and got the error message “Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)”
After about an hour of trying different things and reading all sort of blogs and forums, I finally decided to restart my mac and voila, it worked… At least Windows tells me that I need to restart.
Ok, so I got the GUI MySQL administrator up. I added a database called favewares_development (to follow RoR naming conventions) and created some tables.
If you read anything about Rails you will end up reading the phrase “convention over configuration” a bazillion times; so here is a quick note on database naming conventions:
- Database name = appname_development, appname_test, appname_production
- Table name = plural e.g. authors, wares, stories, categories, etc…
- Primary key name = id
- Foreign keys = singularOfForeign_id e.g. category_id, author_id, etc…
- Many to many tables = tablea_tableb in alphabetical order e.g. items_orders, classes_students
There is more information about Rails and Ruby naming conventions over here.
Database is now created, let’s edit the code. Oops, no code editor – damn it. I went to textmate and downloaded their 30-day trial.
Once I was done creating my tables, I generated the schema.rb file in the project’s db folder in textmate by clicking Bundles > Ruby on Rails > Database > Dump DB to schema.rb
My scheam.rb file looked like this:
Although I didn’t really have much so far, my brain had had enough of being outside its comfort zone – I miss windows…
Stay tuned for the next part of this post.
[update] Part 2 is available here.
Tags: favewares, My Projects, Programming, rails, ror, ruby












Fri, Apr 25, 2008
Programming