This is a really, really simple way to create a new application in Rails 2.0. I will write more when I have the time so that this application is then further developed. However, for now you just need this to start work.The first thing you need to do is make sure Rails is properly install.I’m assuming you have Ruby installed already. If not, go to Ruby-Lang.org to find the relevant installation for your OS.
Open a command shell/prompt of your choice and run:
gem install rails --include-dependencies
..and go make a quick cup of coffee while it does its thing. Once install, you want to create a project folder for all your rails application. For simplicity’s sake I stuck this in MyDocuments\Rails (for my Windows development platform). This will store all your projects from now on. Use the command shell to navigate to the Rails folder you created and run:
rails MyProject
to create your project folders, etc. Rails follows the MVC paradigm. You can read more about this here.
Now you want to go into the project folder you just created. In the case of this tutorial it is ‘MyProject’. The next command you want to get things up and running quickly is the scaffold command.
ruby script\generate scaffold Todo title:string priority:integer done:boolean
This will create a ’skeleton’, otherwise known as a scaffold, for your project. The title:string priority:integer done:boolean part of the code is your database creation. This creates a column with the name of the word -before- the colon of a type specified -after- the colon.
You’re done. You now have a skeleton for you project. Go ahead and load up a server with the command:
ruby script\server
Open the URL http://localhost:3000/todos/ to see what you’ve just created.
NOTE: In the scaffold command we gave the scaffold a name of ‘Todo’. ActiveRecord will automatically pluralise this when you use the scaffolding method, so the URL turns into ‘/todos/’
Have a poke around the files within the project folder and see how the system works. Also, you should check out Akita on Rails for a more in-depth look at Rails 2.0
Posted in Programming, Ruby on Rails
Tags: Programming, rails, rails 2.0, ruby, tutorial