Hi Ruby forum,
I’m pretty new to Rails and Ruby and I’m trying to figure out how to
avoid having ugly stack dumps in my applications. I’m trying build a
Login module following the “Rails Recipes”. It works fine when users
enter correct data, but of course, when the fields are blank there’s an
exception in the UI.
My question is: how do I handle/catch the exception so that users won’t
see the rails messages? I just want to drop them off on the page they
were on with a “you’re being naughty” message.
Here is my model code:
def self.authenticate(username, password) user = User.find(:first, :conditions => ['username = ?', username]) if user.blank? || Digest::SHA256.hexdigest(password + user.password_salt) != user.password_hash raise "Username or password invalid" end user end
def signin if request.post? session[:user] = User.authenticate(params[:username], params[:password]).id redirect_to :action => session[:intended_action], :controller => session[:intended_controller] end end