2010-01-14 86 views
0

我使用Ruby on Rails的restful_authentication插件。所有似乎都很好,除了看起來用戶會話沒有被創建。我有下面的創建方法。看來self.current_user正在設置,但實際會話永遠不會被創建。何時以及如何定義current_user_session。我有我的應用程序控制器中的方法,但這是它總是失敗的地方。Restful_authentication插件不工作

def create 
logout_keeping_session! 
user = User.authenticate(params[:login], params[:password]) 
if user 
    # Protects against session fixation attacks, causes request forgery 
    # protection if user resubmits an earlier form using back 
    # button. Uncomment if you understand the tradeoffs. 
    # reset_session 
    self.current_user = user 
    new_cookie_flag = (params[:remember_me] == "1") 
    handle_remember_cookie! new_cookie_flag 
    redirect_back_or_default('/') 
    flash[:notice] = "Logged in successfully" 
else 
    note_failed_signin 
    @login  = params[:login] 
    @remember_me = params[:remember_me] 
    render :action => 'new' 
end 

Application_Controller

def current_user_session 
    return @current_user_session if defined?(@current_user_session) 
    @current_user_session = UserSession.find 
    end 

    def current_user 
    return @current_user if defined?(@current_user) 
    @current_user = current_user_session && current_user_session.user 
    end 

UserSession機型爲空

回答

0

當你說會話,你實際上意味着一個會話或這是一些restful_authentication的魔力?

我曾經使用restful_authentication,一些舊的應用程序仍然可以。但是,他們使用基於cookie的會話管理而不是用戶會話模型。

0

你使用rails 2.3.5嗎?

我看到使用redirect_to的問題,基本上刪除重定向之前添加到會話中的任何變量。

恢復到2.3.4似乎的解決我的問題,但有一個錯誤的燈塔上的問候一些古怪到會話中軌2.3.x版本

這可能不是同一個問題你,但有花了我幾個小時才意識到恢復固定我的問題,所以可能值得快速測試。

2

如果可以避免,請勿使用restful_authentication。有一些更好的選擇,在那裏,實際上是基於REST和更好的維護:

+0

設計實際上是建立在所謂的監獄長另一顆寶石,這是相當真棒在其本身。 – 2010-01-14 14:38:37