I have an app deployed on heroku which uses postgres. The app is not stable...works sometimes and sometimes gives the custom 500 page error.
Code that it is giving error on:
def login
session[:user_id] = nil
if request.post?
if @user = User.authenticate(params[:user][:userid], params[:user][:password])
session[:user_id] = @user.id
if @user.stores.length > 0
redirect_to(:controller => "admin", :action => "select_store")
else
redirect_to(:controller => "pages", :action => "mainpage")
end
else
flash.now[:notice] = "Invalid user/password combination"
end
end
end
my model looks like:
def self.authenticate(userid, password)
user = self.find_by_userid_and_password(userid, password)
user
end
heroku logs says:
ActiveRecord::StatementInvalid (PGError: ERROR: current transaction is aborted, commands ignored until end of transaction block
: SELECT * FROM "users" WHERE ("users"."userid" = E'sampleuser' AND "users"."password" = E'12345') LIMIT 1):
app/models/user.rb:7:in `authenticate'
app/controllers/admin_controller.rb:6:in `login'
since it is an intermittent error i dont know how to fix it. But is it possible to show the errors on the page?....is it possible to catch errors like these and then still proceed? what would be the best solution