我的印象是,在任何POST,PUT或DELETE操作后Rails都会重新生成form_authenticity_token
。但由于某种原因,POST成功后,用户资源form_authenticity_token
不会重新生成。我可以自由发布尽可能多的时间,因为我一次又一次地使用同一个CSRF令牌。Rails form_authenticity_token在POST请求后不再生
我有一个名称空间API,我使用RABL gem来构建我的回应。这是我所拥有的一切设置...
class Api::V1::UsersController < Api::V1::ApplicationController
...
def create
@user = User.new(params[:user])
render "show", :status => (@user.save ? :ok : :unprocessable_entity)
end
...
end
class Api::V1::ApplicationController < ApplicationController
layout '/api/v1/layouts/application.json.erb'
respond_to :json
before_filter :authenticate_user!
...
end
class ApplicationController < ActionController::Base
protect_from_forgery
end
的后经过精细,有在development.log或安慰$ rails s
日志中没有错误或警告。
我检查了create
方法中的verified_request?
,它返回true。我已经移除了渲染并使用与show.json.rabl
视图相同的代码设置了create.json.rabl
视图...没有骰子。
我正在运行Rails 3.1.3 w/Ruby 1.9.2p290 w/cookie会话存储。
真实性令牌经由请求头(X-CSRF令牌)