[size=medium]ActionController::InvalidAuthenticityToken解决方法[/size]
Rails支持将session放在数据库中管理,当我执行完rake命令,去掉environment.rb里的config.action_controller.session_store这个注释,Rails2.0以上的版本会报一个错,具体如下:
ActionController::InvalidAuthenticityToken in Products#index
Showing products/index.html.erb where line #17 raised:
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
于是上网搜搜,解决方法是到这个文件app/controllers/application.rb,看到这样的描述:
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery #:secret => 'be73f1c53c4d8c3b373da4ebfb6599a2'
于是,把#:secret => 'be73f1c53c4d8c3b373da4ebfb6599a2'前的#去掉,再刷新页面,OK。问题解决,顺便记下来备忘。
Rails支持将session放在数据库中管理,当我执行完rake命令,去掉environment.rb里的config.action_controller.session_store这个注释,Rails2.0以上的版本会报一个错,具体如下:
ActionController::InvalidAuthenticityToken in Products#index
Showing products/index.html.erb where line #17 raised:
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
于是上网搜搜,解决方法是到这个文件app/controllers/application.rb,看到这样的描述:
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery #:secret => 'be73f1c53c4d8c3b373da4ebfb6599a2'
于是,把#:secret => 'be73f1c53c4d8c3b373da4ebfb6599a2'前的#去掉,再刷新页面,OK。问题解决,顺便记下来备忘。
本文介绍了解决 Rails 应用中遇到的 ActionController::InvalidAuthenticityToken 错误的方法。通过设置 protect_from_forgery 的 secret 参数,可以避免伪造请求导致的安全问题。
1008

被折叠的 条评论
为什么被折叠?



