Rails3 Custom Password Validators

As I was writing validators for the User class of a Rails 3 app, I wanted to make sure that people wouldn't use their names, usernames, or email addresses as passwords.
Unfortunately I couldn't find a way to accomplish this with the built-in validators. Fortunately Rails 3 makes it easy to write your own custom validators.

Here's an extract of my User class

The "password => true" tells Rails to call my custom validator which, in this case, has to be called password_format.rb.

I keep my custom validators in /lib/validators, so I need to add the following to my config/application.rb file:

And finally the validator itself:

(Don't forget to write the specs to test this! :-)

Rails3 Mind Map

I find mind maps useful for many purposes. The process of clearing your screen, fullscreening your mind mapping tool, and immersing yourself in a topic of interested is a great brainstorming exercise.

Today, my goal wasn't creativity, it was to build a map of main components of Rails 3. You'll likely find the PDF more useful as its nodes are clickable and refer back to the Rails API (and github in a couple cases where I found documentation to be more useful).

This isn't a comprehensive map. Let me know what I've missed.

(This map was created with MindNode Pro, an easy to use, cheap, and high quality OS X app, proving that sometimes you can have your cake and eat it :-)

No More Excuses! Using RVM to Play with Rails 3

Now that Rails 3.0 is out, it's high time to start using it. But what if you want to keep Rails 2.x around for your current projects? Fortunately, on OS X, there's a simple solution: RVM.

Once you've installed RVM, you'll need to install a version of ruby compatible with Rails 3. There are two choices: 1.8.7 and 1.9.2. Given its new features and speed improvements, 1.9.2 is the one to choose, unless you have particular dependencies on 1.8.7.

Installing 1.9.2 is simple: rvm install 1.9.2. This will download, compile, and install 1.9.2 to a .rvm folder in your home directory.

Once that's done, type rvm 1.9.2 to switch over and rvm info to confirm that you're now running 1.9.2. Note: this will only apply to the current terminal window, here's how to make it the default.

Type gem list and you should see just two gems: rake and bundler.

Now go ahead and install Rails 3: gem install rails. Confirm by way of rails --version and gem list.

That's it, you're done... Now have fun!

What to go back to your previous version of ruby? Just type: rvm system and you'll revert back to your standard ruby installation and the gems that went with it.