Archive for January, 2008

Setting up a Mail server for registration

Wednesday, January 16th, 2008

Almost since the beginning I’ve had RESTful Authentication setup on ArcadeFly, although I’d been too lazy to setup a mail server to test of it’s functionality. For testing this out though, I decided to give Google a shot thanks to an article on how to use gmail as your mail serevr for rails. Very easy to implement, although I’m still unsure on the exact limitations. I don’t expect to reach any of those during development though, so for now it’s going to serve as an easy configuration option between the two PCs I use to code.

With that out of the way time to worry about a few smaller issues. Created a signup form at www.ArcadeFly.com. If you’re curious as to why I’m going with the www prefix, it’s mostly because of the site’s audience. For a mostly tech offering, or a tech blog I understand it makes perfect sense to do it the “right” way and use just the domain (we’re doing that for Adogo), but since this will be mostly video gamers and hopefully some not-as-technical people, adding www seems like the way to go. Non-www still forwards that way of course, and I don’t doubt that there will be a huge intersection of progammers and gamers.

Aside from that I learned a little bit about just how Rails Observers work. Such a simple topic I see why I don’t read too much more about it. There’s surely more to it than I’ve found, but it begins with a “config.active_record.observers” option in the environment.rb file where you point it to a classname. For RESTful authentication, for example, you’d point it to :user_observer. This will handle automatically sending out email messages based on changes to the user object. For instance, the UserObserver class is an ActiveRecord::Observer and shares methods like “after_create”, “after_save” and other points. Very powerful feature that’s easy to implement.

Error messages chugging along

Tuesday, January 15th, 2008

Getting nice looking error messages isn’t easy. It’s easy to use the Rails default (”error_messages_for”) but for the type of errors you’d ideally want you’ll still have to do a little leg work. One nice part it that any form fields that are being output using the Rails form helpers will be wrapped in a div with the “fieldWithErrors” class. This makes adding a red border to problem fields extremely simple.

Also, with the help of the recent post about multiple selects over on railscasts, I was able to add in my country/select fields in a very streamlined way. I’m using the same “address” partial for users and arcades at the moment as well, with that partial including the javascript in the header. Pretty slick just including a partial and having all the javascript just fall into place. For now adding a single arcade is working fine all around, although i’m a little concerned with how my nested resources are starting to become cluttered.

Nested resources are just what they sound like. For instance if you wanted to get a users address, you might go to the url http://localhost:3000/users/:user_id/address/1. That’s a very useful looking URL that you can find a lot from. The downside is that the controller/action this will hit is (by default) address_controller.show. This is the exact same controller/action that is hit when you go to http://localhost:3000/address/1 though! The only difference is that there will be a “user_id” variable passed in. After that though you might handle little things differently like the title, the edit link for that resource, and maybe even the entire page. Aparently you can make this resource go to another controller, like “user_address_controller” for example and not have to worry about this. I’m starting to think this is the way to go for a lot of this.