【发布时间】:2014-11-02 19:35:06
【问题描述】:
我在 api 控制器中更改 session 中的值,但它不会反映下次获取 session 中该变量的值时。这是 api 控制器...
module Api
module V0
class RecommendationsApiController < ApplicationController
def x
r1 = session[:last_id]
r2 = some_function(r1)
session[:last_id] = r2
#doesn't reflect in the session next time this same function is called, and the old value is shown
#though checking the value of session at this point shows the right value been set in the @delegate part of the session
end
end
end
end
这是session_store.rb
Application.config.session_store :cookie_store, key: '_session_name'
application_controller.rb
protect_from_forgery
after_filter :set_csrf_cookie_for_ng
def set_csrf_cookie_for_ng
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
end
protected
def verified_request?
super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
end
这是websiteApp.run 函数。
var csrf_token = $cookies['XSRF-TOKEN'];
$http.defaults.headers.common['X-XSRF-TOKEN'] = csrf_token;
我尝试在config 中设置令牌,但config 块没有$cookies。所以尝试在run中设置headers。
请帮忙。
【问题讨论】:
-
您是否查看过浏览器中的 cookie 以查看该值是否实际到达浏览器?这将告诉您问题是未设置 cookie,还是未读取 cookie。那里有关于如何解密会话 cookie 的帖子
标签: ruby-on-rails angularjs session cookiestore