2

所以這是錯誤我看到:無法轉換爲長整數字符串 - 設計/會話控制問題

TypeError in Devise/sessionsController#create 

can't convert Fixnum into String 

Application Trace | Framework Trace | Full Trace 
app/controllers/application_controller.rb:21:in `set_current_user' 

這是怎麼application_controller.rb外觀:

class ApplicationController < ActionController::Base 
    helper :all 
    helper_method :current_user, :logged_in? 

    protect_from_forgery 
    before_filter :set_current_user 

    def set_xhr_flash 
    flash.discard if request.xhr? 
    end 

    def correct_safari_and_ie_accept_headers 
    ajax_request_types = ['text/javascript', 'application/json', 'text/xml'] 
    request.accepts.sort! { |x, y| ajax_request_types.include?(y.to_s) ? 1 : -1 } if request.xhr? 
    end 


    protected 

    def set_current_user 
    Authorization.current_user = current_user 
    end 

end 

幫助!

編輯1:根據請求,這裏是日誌文件的輸出。

User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("users"."username" = 'test') LIMIT 1 
Completed in 289ms 

TypeError (can't convert Fixnum into String): 
    app/controllers/application_controller.rb:21:in `set_current_user' 

Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms) 
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (340.7ms) 
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (350.6ms) 


Started GET "https://stackoverflow.com/users/login" for 127.0.0.1 at 2011-01-19 17:16:18 -0500 
    Processing by Devise::SessionsController#new as HTML 
nil 
Rendered devise/sessions/new.html.erb within layouts/application (5.9ms) 
Completed 200 OK in 65ms (Views: 15.6ms | ActiveRecord: 0.0ms) 


Started POST "https://stackoverflow.com/users/login" for 127.0.0.1 at 2011-01-19 17:16:31 -0500 
    Processing by Devise::SessionsController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"+SYzwvqO1Kp8GhYwSA9u3plM5A/RNNRFT3wzJICXP6s=", "user"=>{"f_name"=>"First Name", "l_name"=>"Last Name", "username"=>"test", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"Email Address"}, "commit"=>"Submit"} 
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("users"."username" = 'test') LIMIT 1 
Completed in 199ms 

TypeError (can't convert Fixnum into String): 
    app/controllers/application_controller.rb:21:in `set_current_user' 

Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms) 
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (348.3ms) 
Rendered /Users/marcamillion/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (355.7ms) 

任何人都想出任何解決方案嗎?

+1

在set_current_user中,您可以在`Authorization.current_user = current_user`之前添加`logger.info current_user.inspect`並將日誌文件中的輸出追加到您的問題中? – 2011-01-19 21:37:14

+0

@Brett Bender完成。查看更新的問題。 – marcamillion 2011-01-19 22:09:48

+0

奇怪的是,該記錄器調用的輸出出現在SessionsController#new中爲nil(這是正確的,如果他們沒有登錄,沒有當前用戶),但是POST請求中沒有輸出來自該記錄器調用SessionsController#create - 也許set_current_user沒有在那裏被調用?我會嘗試從錯誤發送到SessionsController#create的錯誤消息之前得到一些調試輸出 - 顯然#new行動正如你所期望的那樣工作。希望我可以幫助更多。 – 2011-01-20 17:17:56

回答

2

好,於是我終於找到了答案。數據庫損壞了。一旦我傾倒了整個數據庫,刪除了數據庫文件並重新創建了所有內容 - 我很樂意去。

嘆息

我只是希望我能想出一個辦法,以防止在生產發生。

0

你確定以下是在你正確的whatever_controller.rb中嗎?

before_filter :authenticate_user! 
0

您是否將數據庫密碼設置爲純數字?我的數據庫密碼是111111在開發機器,根據錯誤信息"can't convert Fixnum into String",我想我應該更改數據庫密碼爲非數字「abcdef」,它的工作!