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

标签 ruby internet-explorer session sinatra

当我发帖时,其中一个 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/

相关文章:

ruby - Ruby中的3点方法参数是什么?

javascript - 改变 firebugx.js 以适应 IE 开发者工具

php - 如果 session 存储在文件中,为什么仍然使用 cookie 来存储它们?

javascript - 如何在php中将数组记录从进程页面传递到索引页面?

php - 密码、盐和授权

ruby-on-rails - 使用特定 json 键上的 Postgresql json 列过滤 ActiveAdmin

ruby-on-rails - 无法使用 Assets :precompile 在 rails rake 上复制 NilClass

ruby-on-rails - Rails 将 will_paginate 与组合查询结果结合使用

javascript - 使用 Internet Explorer 时如何只加载一个特定的样式表?

c# - 如何解决此 Selenium 网站证书问题