Help with exceptions in UI

onemind wrote:

   user = User.find(:first, :conditions => ['username = ?', username])

Always challenge code that raises exceptions - there are usually ways around it. Specifically, in a pinch, that could be this:

   user = User.find(:first, :conditions => ['username = ?', username]) rescue nil

(All on one line.)

That has the added benefit of hiding any kind of error, not just "user not found" errors. Because you probably don't need that benefit, you can make things shorter and better at the same time:

   user = User.find_by_username(username)

Any find_by_* method returns 'nil' if the target ain't found.