December, 2007


30
Dec 07

Ruby on Rails

Since I have a long weekend due to the holidays, I thought I would spend some time getting familiar with ruby on rails. RoR just came out with version 2.0 this past month and pretty much all tutorials and resources are centered around previous versions and a lot has changed. RoR is built around the MVC (model, viewer, controller) pattern which is somewhat new to me as well. I wanted to get more familiar with this pattern to better understand ruby but also because the ASP.NET MVC Framework is coming out. I was pretty impressed with scaffolding in RoR. It also demonstrates why RoR is used in many agile environments. You can get a simple web application functionality and database schema by running three commands. This allows you to have working software right away and gradually build upon it. So you can see this in action I thought I would post the steps below. This is assuming you already have ruby is installed. Since I am using a Mac it is already installed and I just had to run a few commands to upgrade. I am using TextMate (30 day trial) which is a popular editor to use when developing in Ruby. You can also work with about 30 other modules for other languages. You can even blog from it.

Create website structure. Open a command line. Type rails movies. This will create an application named movies.

When you open this up in TextMate you will see the structure that was automatically generated for you. Notice that you have folders from controllers, models and views. Also notice that you have a folder called tests for unit tests.

Now you are going to create the movie scaffolding. This will create the classes needed and EVEN the code that will generate the table for storage. To get scaffolding for Movie type the following command as shown:

script/generate scaffold Movie name:string description:text year:integer (Make sure the types are lower cased)

This also specifies the properties of a movie and the type. This will determine the types in the database table and also the fields on the web page.

Notice the new files that were created below.

In the picture above you notice there is a file in db/migrate. This file was generated automatically with scaffolding and this code will generate our database table. You actually code the table in Ruby so that way our application isn’t specific to the type of database. I am using SQLite, however you can use many others such as MySql. Below is the code that is in this file.

To create the database type the following in to the command prompt:

rake db:create

Following that we will run the migration files which is the code that was created two steps up. After you do this the table will be created as defined in the migration files. To create the table enter the following into the command prompt:

rake db:migrate

Our application is now created with basic CRUD functionality for movies. You must start the server though to serve the pages. To do this enter the following into the command prompt:

script/server

Then go to the following address in a browser window and you will see the following windows:

http://0.0.0.0:3000/movies

As you can see with scaffolding, you can get up and running pretty fast once you understand it. Scaffolding, however, is not meant to be used to build your whole website, just enough to get a site that is functional fast. I plan on posting more once I learn more. :) There are not many resources right now for the 2.0 version although. Please feel free to let me know of any resources that you have found useful.

For some basic language/syntax check out:

http://www.sitepoint.com/article/learn-ruby-on-rails/1


22
Dec 07

I finally did it!

I have had a couple of macs in the past, but somehow, I keep getting forced back to windows because most of the development I do is with .net. I have been eyeing a Macbook Pro for the last year and finally got one the other day. I have had it just a little over 24 hours now and I LOVE it. It is probably the nicest piece of hardware I have ever owned. It has an all metal case, built in web cam. backlit keyboard and much more. Apple does think of it all. The power adapter is actually magnetic so if someone was to kick the cord it just comes undone. The best thing about it, and the reason this mac attempt will be successful, is because I am not forced to choose anymore. With boot camp, I have windows installed as well and it is native so it runs just as fast as it would on a PC. If i want to go into windows I just hold down the option key during startup and I can select windows or mac. I installed Windows XP, but you can also install Vista. I just choose XP because I am just using it for development and it isn’t nearly as bloated as Vista. I formated a partition using FAT32 so that way I could share files between windows and os x. I finished installing Visual Studio as well and it runs great. I got a kick out of the setup for Mac OS X. They have the usual setup where you create an account and choose your account image. Well one of the images I could select was a picture of me. For a split second, I was trying to figure out how my computer knew what i looked like, but then I remembered there was a camera built in that had taken my picture. :) I have spent the last day transferring stuff over, but am almost done, then I am going to look for some software. If you are a mac user, please let me know if there are any cool applications that are worth mentioning. I am posting this blog entry using ecto, which is basically like a Windows Live Writer. I also am planning on looking into some development tools for Java and Ruby.

For your enjoyment I have some ads that I found funny!

Vista Wheel

Security