Fri, 28 Aug 2009 23:09:00 GMT

Creating a Rails App (Ritter2 Part 1)

Note: This guide assumes you already have Ruby, Rails, and MySQL set up. For an excellent guide on how to do so look here.

Create a Project
This will be the first part in my series on how to create a Twitterish Rails application. The steps here are for creating this application, but they can also generally be used for any Rails application. Just about every Rails application has the same basic setup. The first thing you want to do is actually create your application. On the command line type:
rails -d mysql ritter2
That will generate all of the basic files you need for your application. I specified that I wanted to use MySQL as my database. The default for Rails is SQLite.

Start Your Application
At this point you have a working Rails site, but it doesn't do much. Go into your ritter2 folder and enter the following command:
That will start up an instance of your application, which you can access at http://localhost:3000. Nothing too exciting here, except that you have a running server in two commands. Go ahead and kill the server with Crtl-C.

Setup a Database User
Now we're going to setup the database for our Rails application. The first thing I always do is generate a new user for my Rails application to use. You can do that with the following:
mysql -u root -p
You will be prompted for your MySQL root password. After that you can enter the following commands:
grant all on *.* to  "ritter2"@"localhost" identified by "ritter2";

Setup Rails Communication to the Database
Now we need to tell Rails how to connect to the the database. We do that in the database.yml file in the config directory of our application. Open that up and put in the username and password for each database. Here's an example:

Create the Database
Now we want to tell Rails to create the databases. To do that run the following command from the application root:
rake db:create:all
That will create your databases for you.

In the next part of this series I will go through some of the key aspects of setting up authentication for a Rails application.

Sun, 23 Aug 2009 20:21:00 GMT


Once upon a time I wrote a Rails application called Ritter. It was for my Principles of Information Systems class and in my opinion exhibited everything that class was about. It is a twitter clone (approximately) smashed together with my alma mater, RIT. Anyways, the reason I bring this up is because I'm planning on writing a series of articles on how to write a similar application.

If you want to see a live demo you can check it out here.
The source code is available on github.