2010-01-24 49 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 

希望它會有幫助!