I finally did the rewrite of Barspin.com.
Barspin is a BMX web site for bay area BMX riders. I created it many, many years ago with my friend Ryan. For the past year and a half nobody has posted anything on it. Pretty much, it was a dead site. Well... except for all the spam. Spammers were hitting the site twice a day with junk posts.
A few weeks ago I pulled the plug on it. I was so sick of cleaning up spam and removing faked accounts that I just didn't want to deal with it anymore. Well, Ryan didn't like that too much and wanted to have at least the photo gallery up.
So last week I thought to myself, "what a great project to get some more Ruby on Rails experience." So I re-wrote the site in Ruby on Rails. I wanted to keep it very simple, but I still wanted to have some nice features to it.
The plan: Photo gallery and live chat. So I created a simple layout for a two pane interface. One side is the photo gallery, the other is the chat. Very simple.
I did the chat first because it was the easiest to do. I had already wrote a live chat in PHP for another customer. I just had to take the parts needed to make it go and set it up in Ruby. Easy as pie. The chat uses Flash Player 8 or better to connect to a socket server. The socket server just mirrors whatever is sent to it. Then the Flash app relays the data using JavaScript. You know, a JavaScript / Flash gateway. Since I can't connect to sockets using JavaScript I needed to use Flash.
Why not just use AJAX? Because AJAX polls the server every few seconds to update the chat display. I would need to have some type of queue to hold the messages then pass them to JavaScript for display. That means a database of something. Also, there is a lag between input and output. With a socket, everything is real time, and I don't need storage. It goes in, it goes out, and all is good.
OK, so the chat is out of the way, now on to the Photo Gallery. This part was much harder because I didn't know anything about how Ruby handles files and such. I finally figured out how to get a directory listing with DIR and just find the .jpeg files. Then I figured out how to sort them. Then display them...although that wasn't that hard.
Then I ran into another hard part. I wanted to use Lightbox to display the full size photos. And on top of that, I wanted to only show 9 photos at a time with a pager. Lightbox doesn't really work that way. I'm using DHTML to build the photo list. So I had to figure out how Lightbox worked. Digging into the code I figured out that I can remove the children from the body tag for the LightBox parts. Then reinitialize the Lightbox script to build the new effect. Easy. So when the page is advanced forward or backwards, the script removes the old lightbox magic, then builds new Lightbox magic.
I still have more work to do on it. I have to create a way for other people to add photos to the gallery and, per Ryan's request, add photo albums.
It's all good in the hood.