gpt4 book ai didi

ruby - 在 Internet Explorer 上发布期间 Sinatra session 丢失

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:06 24 4
gpt4 key购买 nike

当我发帖时,其中一个 session 变量在 IE 中丢失了。

此网络应用在 Chrome 和 Firefox 中完美运行。

这里是错误:

NoMethodError at / 

undefined method `include?' for nil:NilClass
file: welcometo.rb
location: xml_file_to_use
line: 19

错误的方法如下:

def xml_file_to_use
groups = allowed_groups
#Which xml file should I write to
if (session[:location_group].include? allowed_groups[0] ) <----Line 19
......
end

这是一个解释和我的代码:

当用户登录时,设置 session 变量:

#Check to see if the user is authorized
auth_token = Adauth.authenticate(params[:user], params[:password])
if auth_token
session[:user] = params[:user]
session[:first_name] = auth_token.first_name.tr('/"[]', '')
session[:location_group] = (auth_token.groups & allowed_groups)
redirect '/'
else
redirect '/login'
end

接下来我根据这些 session 值设置变量:

get '/' do
if session["user"] != nil
@first_name = session[:first_name]
@groups = session[:groups]
@xml_file = xml_file_to_use
@location = location
erb :form
else
redirect '/login'
end

end

这部分工作得很好。我知道是因为我在我的 View 中使用了@location 变量。

定位方法如下:

#Setup Location Variable
def location
if (session[:location_group].include? allowed_groups[0] ) <-- This same code errors during a post in IE
return 'Eagan'
else
return 'Chicago'
end
end

最佳答案

Konstantin Haase 是正确的,这一定是一个错误。

从他发布的链接中,我发现将它放在我的 welcome.rb 文件的顶部可以解决问题:

set :protection, except: :session_hijacking

关于ruby - 在 Internet Explorer 上发布期间 Sinatra session 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12220882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com