携帯電話の機種に応じて Mobile::xxx を返す。 携帯電話でない場合はnilを返す。
# File lib/jpmobile/request_with_mobile.rb, line 40 def mobile env['rack.jpmobile'] end
携帯電話からであれば true
を、そうでなければ false
を返す。
# File lib/jpmobile/request_with_mobile.rb, line 29 def mobile? mobile and not mobile.smart_phone? end
for reverse proxy.
# File lib/jpmobile/request_with_mobile.rb, line 13 def remote_addr if respond_to?(:remote_ip) return __send__(:remote_ip) # for Rails elsif respond_to?(:ip) return __send__(:ip) # for Rack else return ( env["HTTP_X_FORWARDED_FOR"] ? env["HTTP_X_FORWARDED_FOR"].split(',').pop : env["REMOTE_ADDR"] ) end end
viewの切り替えをするかどうか
# File lib/jpmobile/request_with_mobile.rb, line 34 def smart_phone? mobile and mobile.smart_phone? end
環境変数 HTTP_USER_AGENT を返す。
# File lib/jpmobile/request_with_mobile.rb, line 8 def user_agent env['HTTP_USER_AGENT'] end
環境変数 HTTP_USER_AGENT を設定する。
# File lib/jpmobile/request_with_mobile.rb, line 24 def user_agent=(str) self.env["HTTP_USER_AGENT"] = str end