Using @request.user_agent to determine if someone is using I

Hello:

I’d like to use @request.user_agent to determine if someone is using
IE. So I thought the line

if @request.user_agent=“Microsoft Internet Explorer” would be a bit of
programming genius. Sadly, it does not work and the complaint from
rails is "no = method for @request.user_agent. Interesting. So I tried
@request.user_agent.include(“Microsoft”) and apparently there is no
include method either. I tried to look up user_agent in the docs to
find out what it methods it did have and can find nothing on the
subject.

For 5 Karma points - what is the solution?

bruce

I just answered my own question. Not sure why it did not work when I
tried it earlier. Here is a solution for others who want to do the same

if @request.user_agent.include?(“Microsoft”) then @browser = ‘MSIE’
else @browser = “other” end

@request.env[“HTTP_USER_AGENT”] =~ /Microsoft Internet Explorer/

actually, that should be

@request.env[“HTTP_USER_AGENT”] =~ /MSIE/

Actually it should be request, not @request. @request, @params et. al
are deprecated.

Hey,

I think, more fundamentally, the reason your fist attempt failed is
that you were using the ‘assignment’ operator (=) instead of the
‘equals’ operator (==).

Eric