2010-09-14 56 views
1

我在Rails 2.3.9中得到這個錯誤,但在2.3.8中沒有。我沒有改變任何代碼。我錯過了什麼嗎?SessionsController中的ActionController :: InvalidAuthenticityToken#創建錯誤

ActionController::InvalidAuthenticityToken in SessionsController#create ActionController::InvalidAuthenticityToken 

謝謝:)

這裏是添加細節。

Request 

Parameters: 

{"commit"=>"Login", 
"authenticity_token"=>"A9A4+sCsA/81FFoXJEUNziQYhgQ38pceGN2i7MUQbQY=", 
"password"=>"r3dp0rt"} 

下面是應用控制器

class ApplicationController < ActionController::Base 
    helper :all # include all helpers, all the time 
    protect_from_forgery :secret => "[email protected]$$", :digest => "MD5" # See ActionController::RequestForgeryProtection for details 

下面的代碼是從我的會話代碼創建控制器

def create 
    session[:password] = params[:password] 
    flash[:notice] = "Sucessfully logged in" 
    redirect_to "/login" 
    end 

,最後在這裏是從我的簡單登錄查看代碼

<div id="placeholder"> 
    <% form_tag :action => "create" do %> 
    <p> 
    <%= label_tag "This will enable administrative features for the site." %><br> 
    <%= password_field_tag "password" %> 
    </p> 
    <br> 
    <p> 
    <%= submit_tag "Login" %> 
    </p> 
    <% end %> 
</div> 

回答

3

2.3.9中存在一個錯誤。它防止在使用activerecord或memcache會話存儲時設置會話ID。看到這個rails ticket。您可以使用Mislav的補丁在http://gist.github.com/570149上修復它。您必須創建並粘貼config/initializers/sessions_patch.rb中的代碼。或者你可以在你的項目的根路徑運行以下命令:

wget http://gist.github.com/570149.txt -O config/initializers/sessions_patch.rb 

最後不要忘了重新啓動服務器(以及可能發出rake db:sessions:clear)。

+0

偉大工程。謝謝:) – 2010-09-20 01:14:10

0

H你試過清除瀏覽器的瀏覽數據嗎?很可能它仍然在發送舊的AuthenticityToken。

+0

是的,我做到了,但沒有運氣:( – 2010-09-15 00:27:06

1

我沒有足夠的積分作爲對已接受答案的評論,因此我將添加此答案作爲答案。該修補程序可以正常工作,但只需要小心地將其命名爲sessions_patch.rb,以便在session_store.rb之後按字母順序排列。由於我發現了困難的方法(錯誤地命名了修補程序session_patch.rb,初始化程序的順序很重要,如果在您的密鑰和密鑰設置在session_store.rb之前加載該修補程序,修補程序將不起作用。希望這可以爲某人節省一些時間。

相關問題