部署到heroku的app不稳定

时间:2010-01-31 17:13:22

标签: ruby-on-rails

我在heroku上部署了一个使用postgres的app。该应用程序不稳定...有时工作,有时会给出自定义500页错误。

它给出错误的代码:

  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

我的模型看起来像:

  def self.authenticate(userid, password)
    user = self.find_by_userid_and_password(userid, password)
    user
  end

heroku日志说:

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'

因为这是一个间歇性的错误,我不知道如何解决它。但是有可能在页面上显示错误吗?....是否有可能捕获这些错误然后仍然继续?什么是最好的解决方案

1 个答案:

答案 0 :(得分:0)

尝试自定义查找:

  def self.authenticate(userid, password)
    user = self.find(:first, :conditions => {:userid => userid, :password =>password})
    user
  end