Links
Whiny Finder
Categories
Whiny Finder
- Add "!" to your regular finder methods to raise an ActiveRecord::RecordNotFound error if an empty array is returned
- Works for find! as well as dynamic find_[all_]by_*! methods
Example:
def reset_password
@user = User.find_by_login!(params[:id])
@user.password = "changeme"
@user.save
flash[:notice] = "#{@user.login}'s password was reset!"
rescue ActiveRecord::RecordNotFound
flash[:error] = "No such user."
ensure
redirect_to :action => 'index'
end
Vitals
| Home | http://soen.ca/projects/svn/rails/plugins/whiny_finder |
|---|---|
| Repository | http://soen.ca/projects/svn/rails/plugins/whiny_finder |
| License | Ruby's (MIT) |
| Tags |
find
|
| Rating | (3 votes) |
| Created | 14 August 2006 |

