AWebFactory
Demo App Part2

Now that we have something elemental running in our Rad Rails environment, we are going to make some enhancements, so we need to put the project under version control: Subversion, of course!

Generating the SSH keys

I got my Development Environment ideas from an informative thread here on the Site5 Ruby Forum called OVERVIEW: setting up ROR, SVN and Switchtower on Site5. This pointed me to an interesting page which explains, among other things (like which editor to use for Ruby on Rails on a Mac), how to generate and use SSH keys.

So, what did I do, exactly?

On my home box I did the following:

victorkane@mentor:$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/victorkane/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/victorkane/.ssh/id_rsa.
Your public key has been saved in /home/victorkane/.ssh/id_rsa.pub.
The key fingerprint is:
80:a3:a2:93:7a:01:c3:07:25:b7:a4:1d:55:45:06:21 victorkane@mentor

Copying the public key to AWebFactory:
victorkane@mentor:~$ scp .ssh/id_rsa.pub awebfact@awebfactory.com.ar:.ssh/
awebfact@awebfactory.com.ar's password:
stdin: is not a tty
id_rsa.pub                                    100%  399     0.4KB/s   00:00
victorkane@mentor:~$                                                         

Afterwards in an ssh shell in AWebFactory:

awebfact@lapetus [~]# cd .ssh
awebfact@lapetus [~/.ssh]# cat id_rsa.pub > authorized_keys
awebfact@lapetus [~/.ssh]# ls -l
total 16
drwxr-xr-x   2 awebfact awebfact 4096 Feb 25 17:01 ./
drwx--x--x  18 awebfact awebfact 4096 Feb 25 16:54 ../
-rw-r--r--   1 awebfact awebfact  399 Feb 25 17:01 authorized_keys
-rw-r--r--   1 awebfact awebfact  399 Feb 25 16:46 id_rsa.pub

Creating the SVN repository on AWebFactory

awebfact@lapetus [~]# svnadmin create --fs-type fsfs ./repos
awebfact@lapetus [~]# cd repos
awebfact@lapetus [~/repos]# ls
./  ../  README.txt  conf/  dav/  db/  format  hooks/  locks/

Setting up the new repository in Rad Rails

Following the Site5 Ruby Forum thread, there is an excellent comment added on about Subclipse and Subversion svn+ssh://

I already had Subclipse installed, so, as per the above thread, I did

click Window -> Show View -> Other
And select "SVN Repository"

Once in the view I clicked on the “Add Repository button” and filled in the URL in the dialog box that popped up:

I clicked and then filled in the SSH credentials (notice “use private key authentication” is checked, the private key file is specified, and also in my case I had specified a passphrase when I generated the public/private pair) in the next dialog:

and was rewarded with the new repository listed in the SVN view.

So, let’s import our project into the repository, from our local development box to the repository we have just set up on the Site5 server host, AWebFactory. We right-click on the project folder “demo [demo]”, and from the menu we select “Team/Share Project”. We are then asked to choose between CVS and SVN (an easy choice :) ):

In the “Share Project with SVN Repository” dialog, we opt to use an existing repository location (which will be made for us automatically) in the repository we have just created:

It trundles for a while, makes an initial commit and checkout (see below at bottom), that is, import, and then presents the Commit dialog, which we fill in appropriately, for revision 2, and in our case hit the “select all” button to commit all the files:

The process is recorded in the log at the Console view at the bottom of the screen:

We can now visually browse the repository in the repository view:

And if you now go back up to the Rails Navigator, and do right-click on the demo folder, indeed, on any folder or file, and then mouseover “Team” on the menu, you will see many powerful features, similar or analogous to the similar (but not exactly the same) TortoiseSVN client very popular on Windows.

So now let’s use the repository (in a very simple way, we aren’t using branches and tags yet, we’ll do that for the next demo, which will deal with the Depot application in the Agile Web Development with Rails book), and go ahead and make the changes outlined on page 32; let’s add some dynamic content to the view.

The view is found at /demo/app/views/say/hello.rhtml :

Let’s go ahead and type in the dynamic code, and save our work:

<html>
  <head>
    <title>Hello, Rails!</title>
  </head>
  <body>
    <h1>Hello from Rails!</h1>
    <ul>
      <li>Addition: <%= 1+2 %> </li>
      <li>Concatenation: <%= "cow" + "boy" %> </li>
      <li>Time in one hour: <%= 1.hour.from_now %> </li>
    </ul>
  </body>
</html>

Jeez, as a refugee from J2EE and JSP, this stuff sure looks famailiar (except without all the hassle). Now head over to the Servers view, select the “demoServer” and if it is stopped, start it:

It worked!
(notice I am using port 3001, you will probably be using port 3000, so your url will probably be http://localhost:3000/say/hello
If you compare the code we added to hello.rhtml with the html output, you can see that the string found between <%= and %> is interpreted as ruby code, executed, and its output placed in the resulting view returned in the display:

Since we’ve tested it and know that it works, it’s time to commit our changes to the AWebFactory repository. Go ahead and right click on the demo folder, and choose Team/Commit from the menu. Enter the appropriate details, make sure the changed files are checked (they should be automatically already) and hit the OK button:

The commit is carried out, and we can see the revision number “3” next to hello.rhtml in the Rails Navigator:

Content Copyleft Victor Kane (ProjectMaster) and awebfactory.com.ar
Email me at info at awebfactory dot com dot ar
Full content (RSS 2.0) and Headlines (RSS 2.0)