【发布时间】:2012-08-26 14:21:46
【问题描述】:
当我发帖时,其中一个会话变量在 IE 中丢失了。
这个 web 应用在 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
这是一个解释和我的代码:
当用户登录时,会话变量被设置:
#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
接下来我根据这些会话值设置变量:
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
这部分工作得很好。我可以说出来,因为我在视图中使用了@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
【问题讨论】:
-
这是机架生产中已知且难以追踪的错误。 (不)幸运的是,它不经常浮出水面。请加入讨论:github.com/rkh/rack-protection/issues/11
标签: ruby internet-explorer session sinatra