Skip to content

Commit 58a0017

Browse files
committed
Fix bug when user agent header is uncommon (e.g. google crawler)
1 parent 84edc5d commit 58a0017

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app/helpers/application_helper.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module ApplicationHelper
22
# 获取操作系统
3+
# os.mac?
34
def os
4-
os = case request.user_agent.downcase
5+
os = case (request.user_agent || "").downcase
56
when /iphone|ipad|itouch/
67
"ios"
78
when /android/
@@ -10,8 +11,10 @@ def os
1011
"mac"
1112
when /windows/
1213
"win"
14+
else
15+
"unknown"
1316
end
14-
return ActiveSupport::StringInquirer.new(os)
17+
ActiveSupport::StringInquirer.new(os)
1518
end
1619

1720
# 导航项是否高亮,手工设置 @curr_nav 变量来实现

0 commit comments

Comments
 (0)