Start Your Own Campfire
After marvelling over the idea behind Campfire, I wondered how easy Rails would make it to start my own campfire. After all, the concept doesn’t seem to be all that complex: log people’s messages and feed them back to all the other people in the same chatroom. There’s some bells and whistles around that, like logging in, creating your own room, inviting others to join your room, etcetera. But I think, if you’ve got the basic concept covered, the rest will follow easy enough. And that basic concept didn’t proof to be all that hard to build — with Rails.
First, I created a very simple database table to hold all messages with a timestamp and username for each message. Then I created my Rails application, with one model class for the messages and one ChatController. ChatController contains an index
method that initially reads all messages from the database and passes them and a fresh new Message object to the view. There’s a create
method that will store a newly entered message in the database. And finally there’s a refresh
method for periodically refreshing the div
in the view that contains the message log. The index.rhtml
displays the messages using a _messages.rhtml
partial that is also used for refreshing them, with a periodically_call_remote
call. To add some more Ajax, newly entered messages are sent back with a form_remote_tag
, so the visitor never sees the screen blank for server requests.
That’s it, really. Nothing more to it. For the basics, anyway. I could think of a ton of features I’d like to add. First thing I’ll do is to add authentication; then put it on DreamHost and tell my colleagues and friends. We won’t be needing Campfire’s services, thank you very much. Blame Rails for making it easy.
Download the source here: Kampvuur (Dutch for Campfire) 0.1 BETA
2006-02-21. One response.
buy hgh 1000…
buy hgh 1000…