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

(null)

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:

  1. Open a terminal window 
  2. Run rails /users/emad/code/favewares
  3. Run cd path/to/your/new/application
  4. Run ruby script/server

Then I opened http://localhost:3000 in my browser and got to the welcome page shown below.

RoR Welcome aboard

Time to create the database, so I had to go download MySQL and install it which was surprisingly very straight forward:

  1. Double click the MySQL installer
  2. 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)”

mysql connection error

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.

mysql administrator

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:

  1. Database name = appname_development, appname_test, appname_production
  2. Table name = plural e.g. authors, wares, stories, categories, etc…
  3. Primary key name = id
  4. Foreign keys = singularOfForeign_id e.g. category_id, author_id, etc…
  5. 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

Dumb db to schema.rb

My scheam.rb file looked like this:

schema.rb

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.

Advertisements

0 thoughts on “Ruby on Rails for a .NET Developer – Part 1

  1. Good for you! I admire that you’re stepping out of the ‘.NET’ zone for a bit to try something new. I promise you won’t be disappointed Rails.I’m actually trying to convince my company to switch from .NET to Rails. It’s going to be tough, but going to be SO worth it in the end. Good luck!

    Like

  2. Good for you! I admire that you’re stepping out of the ‘.NET’ zone for a bit to try something new. I promise you won’t be disappointed Rails.

    I’m actually trying to convince my company to switch from .NET to Rails. It’s going to be tough, but going to be SO worth it in the end.

    Good luck!

    Like

  3. Hi Emad,welcome to Rails-land! 🙂 A few things to consider:1) When creating a project, you can specify a “-d mysql” option in order to have the config/database.yml file filled with MySQL specific information, given that the current default is SQLite.2) You don’t have to manually create the databases. Simply run: rake db:create:all from your project. For a complete list of available tasks, run: rake -T3) You may want to consider starting to use migrations, rather than defining the tables directly through SQL or MySQL tools.Best of luck,Antonio

    Like

  4. Hi Emad,

    welcome to Rails-land! 🙂 A few things to consider:

    1) When creating a project, you can specify a “-d mysql” option in order to have the config/database.yml file filled with MySQL specific information, given that the current default is SQLite.

    2) You don’t have to manually create the databases. Simply run: rake db:create:all from your project. For a complete list of available tasks, run: rake -T

    3) You may want to consider starting to use migrations, rather than defining the tables directly through SQL or MySQL tools.

    Best of luck,
    Antonio

    Like

  5. @Jonatha thanks. It’s a little challenging being that everything is different, OS, tools, platform, syntax, language, etc… I am lucky I have been playing with asp.net mvc because the transition is a little easier.@Antonio great tips. thanks…One thing that sucks so far has been the documentation.

    Like

  6. @Jonatha thanks. It’s a little challenging being that everything is different, OS, tools, platform, syntax, language, etc… I am lucky I have been playing with asp.net mvc because the transition is a little easier.

    @Antonio great tips. thanks…

    One thing that sucks so far has been the documentation.

    Like

  7. Pingback: Free IT Consultation in the DC Metro Area | Emad Ibrahim

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s