Doing Ruby on Rails with Netbeans 6.0
I came across a book on RoR titled Railspace. A very good book for both starters and professionals. The book however relies heavily on the ruby command line to perform many of its tasks. I am using this opportunity to try to create a walk through the Ruby Application Framework support of Netbeans 6.1 beta. Its really cool seeing Netbeans do so much of what I will normally do in ruby console. It really saves me time by not making me repeat myself (DRY).
To start with, Install the Netbeans 6.1 IDE (you can get it from sun's web site). This automatically installs Jruby and other things you need to build a RoR application. Surprisingly, that is all you need, no other PlugIns, no other applications, nothing more. Just this wonderful Netbeans IDE, isn't that a very beautiful place to start from? I have seen tutorials where I have to install virtually everything on the Internet before I could make it work, but for RoR on Netbeans; all you need is Netbeans IDE.
After Installation, You are ready to go, follow these simple steps
1.Start the Netbeans IDE (if you have not already done so). Below is a screen shot of the IDE.

2.Click on File and select new project.

3.Under categories, select Ruby, and Under Projects select Ruby on Rails Application.
4.Click Next.
5.Specify the options as appropriate on this page. The most Important option here is the Project Name and Project Location. Leave other options in their default values.

6.This tutorial assumes you already had a hands on experience on RoR, so you should know the importance of this page and you should already be excited at what this will do for you. Netbeans has in-built database drivers and so on this page, if you want Netbeans to create a the databases you need for RoR for you just pick New Database Connection under any of the databases and specify the parameters as appropriate. I don't need to tell you how to do this except you are a newbie to computers and programming, which means this tutorial is not for you. But if you already have a database connection and you have created a database then use the Specify Database Information Directly Option. I used the first option and here is one screen shot for you. The basic settings are enough for you at this stage. If you like you can explore the Advanced settings though. Make sure you have created the database called oneclassmate.

7. Click next and ......let sleeping dogs lie by clicking Finish
You have successfully created You first RoR Application. Allow some time for Netbeans to create your Directory Structures. The first thing you notice is that Netbeans have run rails command for you. Yes you don't have to run rails from the command line again. Never! and database.yml must have also been created for you. That is good news ain't it? As from now on the rest of this tutorial is just a matter showing you what you would have seen if I had given you some time all by yourself.
8.Next, run the project by pressing F6 on your keyboard or clicking run on the IDE. This will open a web browser automatically and here's what you should see on the browser.

Try some or all of the links to see what they do[This is not a RoR tutorial, remember?].
We are almost done, now lets see how you do some basic tasks using Netbeans
1.Generating a controller
a)Right click on the project and click Generate...... This open a page where you have options to generate so many things, you can see them for yourself cant you?
b)To generate a controller, make sure controller is selected and type the name in the text box provided for Name. To generate actions for the controller, type a space after the name of the controller and type the action(s) also separated by space. See the screen shot below. You can also generate Views(optional). There are also other options on this page to make life easier for you.

Don't be afraid, try them out ok? After clicking OK, three very important files among others are created for you
1.the controller you just specified
2.the helper file for this controller
3.the test file for this controller
Don't forget to always look at the output panel below your screen you have very important information there. Don't forget to look at the left hand panels too, there you have your directory structures. For those who don't know, your views are found in the Views Folder (lol).
2.For command line lovers, you can still run the Rails Console just right click on the project and pick Rails Console, the console is opened on the output panel, here you can type your commands and do stuff you know! And for those who love the Ruby shell, yes we have that also in Netbeans. Click Window menu ==> Select Other ==> select Ruby Shell (See screen shot below). The console is also opened on the output panel.
3.You can also run any Rake task you want to from migrate, to testing, to create, to drop, to rollback just about any Rake task you know (and the ones you don't know!). Right click on the project again, pick Run Rake Task and you have all the rake tasks there are. You can also run debug on any of these tasks by selecting debug rake task. The beautiful thing is that Netbeans uses Action-Aware-Menus. You recent actions are listed at the top so you have them close by.
Well this is as much as my hands can type for now. You need more help, mail me or call
segun@accessng.com
2348089370313
No comments:
Post a Comment