Ruby on Rails
Whiny Finder Plugin (Version #6)

Description

  • adds find! method raising an ActiveRecord::RecordNotFound error if an empty array is returned
  • adds the same methods for find_by___COLUMN_NAME__! methods as well
  • Both of these methods work exactly like Rails core find and find_by methods

Example:

__admin_controller.rb__


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] = “Could not reset user’s password, unknown user.”
ensure
redirect_to :action => ‘index’
end

svn: http://soen.ca/svn/projects/rails/plugins/whiny_finder/trunk

Description

  • adds find! method raising an ActiveRecord::RecordNotFound error if an empty array is returned
  • adds the same methods for find_by___COLUMN_NAME__! methods as well
  • Both of these methods work exactly like Rails core find and find_by methods

Example:

__admin_controller.rb__


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] = “Could not reset user’s password, unknown user.”
ensure
redirect_to :action => ‘index’
end

svn: http://soen.ca/svn/projects/rails/plugins/whiny_finder/trunk