ROR User System: Part 2 – Generic Registration Time

Today we continue our adventure in Ruby creating a Last time we set-up the general background support for the system. Today, we’re going to make some magic appear on the screen, and get some data on our pages.

Making it Run

To get started, let’s just make sure we have things all well in the Ruby world. You should still have a command prompt open and your favorite editor. In the command prompt, let’s do the following:

ruby script/server

You just started the ruby server on your computer. Where did it come from? From when you installed ruby of course! Now, go to your internet browser and enter:

http://localhost:3000/

This is the address of your local machine and the ruby server. You should see something like this:

Ruby Running Screenshot

Yah! It works! Okay now. Time to get this thing going.

Setting Up the Controller — just like a remote control

The time has come to see something on the screen. For this project, we’re going to really just focus on using one controller. Remember, a controller is the gateway between what the user sees and interacting with the database. We’re going to use this project as a portal for other projects, so, let’s call the controller: portal.

Open another command prompt (leaving the other one opening and running) and in your command prompt, type the following:

ruby script/generate controller portal

This will run and create a handful of things in your project. The main thing this will create, in the app folder, a controller! Yah! (That was our goal and all.) You’ll notice the file is called: portal_controller.rb. The convention in ruby is to use the underscore for files/variables/etc with multiple words. Notice we also have a folder under app for views called portal. This will come in handy in a little bit.

Open the portal_controller.rb file and let’s get some things going. When you start, you’ll see just this:

class PortalController < ApplicationController
end

Just like any other coding language, everything we code has a beginning and an end. In ruby, we use the term end as our ender. In our file, let's add the following in between the class and end lines:

scaffold :user

This will create a real generic scaffold (set of guides) for our portal controller using the user class. Now, we can play around with our file and still have functionality. Point your browser to: http://localhost:3000/portal. In ruby, we put the controller we want to use after the localhost:3000. So, if we wanted to look at a zoo_keeper controller, we'd browse to: localhost:3000/zoo_keeper.

You should see this:

Listing Users - Scaffold

Sure, it's nothing pretty -- but it is pretty cool. With the scaffold being used, we have created a simple CRUD interface. No, not nasty grim, CRUD - Create, Read, Update, and Delete. With this we can add new records, view records, edit, and delete them. Go ahead, click around, add some files. Here we've added a user and you can see he now has show, edit, and delete functions.

List w/ Bob Newhart

Notice the nice green message at the top -- Ruby is great at keeping us posted with what's going on. In this case, we've successfully created a user.


Play around a bit with the site. Next time we're going to make it do a few more things which we'll need it to do -- like make sure any required fields are completed, making the password secret, and adding our safety net for account deletion. Until then!Note: You can right-click and view image to see the a better image resolution. Next time I'll probably be putting these on a video, so we'll not have this prob again.

There are no comments yet. Be the first and leave a response!

Leave a Reply

Wanting to leave an <em>phasis on your comment?

Trackback URL http://www.matthewvb.me/2007/02/11/ror-user-system-part-2-generic-registration-time/trackback/