2010-01-24 47 views
1

我有一个小型的免费应用程序在heroku上运行。heroku目前的交易已中止

间歇性的应用程序停止工作,并在屏幕上显示默认的heroku错误页面。当我检查日志我看到以下内容:

ActiveRecord::StatementInvalid (PGError: ERROR: current transaction is aborted, commands ignored until end of transaction block : SELECT * FROM "users" WHERE ("users"."password" = E'' AND "users"."userid" = E'') LIMIT 1): app/models/user.rb:5:in authenticate'
app/controllers/admin_controller.rb:6:in
login'

在我的控制器

我只是做以下几点:

user = User.authenticate(params[:storeid], params[:password]) 

,并在用户模式:

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

错误消息导致我相信有些关系是悬而未决的。这是一个在Ruby应用程序中的情况吗?

在我的应用程序中也有很多地方我使用find_by_sql。这是否要求我们明确关闭连接?

像这样:

@sqlstmmt1 = "INSERT INTO addresses (\"line1\", \"line2\", city, state, zip, county) VALUES ('" + params[:line1] + "', '"+ params[:line2] + "', '"+params[:city]+ "', '" + params[:state] + "', '" + params[:zip]+ "', '" + params[:county]+"')" 
sql = ActiveRecord::Base.connection(); 
sql.begin_db_transaction 

回答

0

我得到这个错误原因是什么,我认为是试图插入UTF-8字符的时候,所以我想你的密码可能有异国情调的字符。顺便说一句:你应该转义你使用的sql-string,嵌入参数[:任何东西]都是baaaad。

0

我是越来越类似的错误,这一点Rails文档的帮助:

http://apidock.com/rails/ActiveRecord/Transactions/ClassMethods

Warning: one should not catch ActiveRecord::StatementInvalid exceptions inside a transaction block. ActiveRecord::StatementInvalid exceptions indicate that an error occurred at the database level, for example when a unique constraint is violated. On some database systems, such as PostgreSQL, database errors inside a transaction cause the entire transaction to become unusable until it’s restarted from the beginning. Here is an example which demonstrates the problem:

...

0

我刚刚重新启动的应用程序,一切又回到右

heroku restart 

希望它会有帮助!