2010-09-14 55 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之前加载该修补程序,修补程序将不起作用。希望这可以为某人节省一些时间。

相关问题