I know almost nothing about programming/coding for the web (basic HTML only) and I’m trying to get my feet wet. I am running Mac OS X 10.5 (Leopard) and wanted to try out Ruby on Rails since I learned of its supposed simplicity. I agree it is simple to use, but I still got hung up in trying to find tutorials as a starting point, in part because the ones I found were for Rails 1.x syntax, whereas I wanted to develop on 2.x.
There are a number of tutorials out there that I found helpful. The most useful one comes from Akita on Rails, posted December 12, 2007. The tutorial comes from Akita’s screencast, which is full of good information, but a bit fast to follow for newbies like me.
The following is a direct parallel to Akita’s work, but I have omitted some details to make for a very quick tutorial for newbies. Follow along to make a very basic to-do list web application.
After installing MySQL Community Server 5.0.45 for x86 (package format, link) and starting the daemon, do the following in the directory where you want your first app to reside:
Create the directory structure for the app by typing:
$ rails todo
Edit the “development” section of config/database.yml to read the following (assuming you are using the root user with no password for local database access). TextMate is recommended because it shows the directory structure so you can easily edit multiple files in a directory tree.
adapter: mysql
database: todo_development
username: root
socket: /tmp/mysql.sock
Let rake (Ruby counterpart of “make”) create the SQL databases for you:
$ rake db:create:all
Make the skeleton (or “scaffold”) of the app (all one line):
$ script/generate scaffold task title:string description:text complete:boolean
Use rake to complete the migration:
$ rake db:migrate
Start the server:
$ script/server
Now you should be able to navigate to http://localhost:3000/tasks and add entries to the to do list. Notice that the path is the plural of name of the scaffold you created.
If I get my act together, I will post a quick tutorial for installing Ruby on Rails and MySQL soon.