# Using @request.user\_agent to determine if someone is using I

**URL:** <https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299>\
**Category:** Rails\
**Created:** [August 24, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299 "2006-08-24T17:32:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299/1 "2006-08-24T17:32:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2006, 5:46pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299/2 "2006-08-24T17:46:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2006, 5:48pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299/3 "2006-08-24T17:48:24Z")

</div>

@request.env[“HTTP\_USER\_AGENT”] =~ /Microsoft Internet Explorer/

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299/4 "2006-08-24T18:02:24Z")

</div>

actually, that should be

@request.env[“HTTP\_USER\_AGENT”] =~ /MSIE/

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 24, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299/5 "2006-08-24T19:02:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 26, 2006, 12:16pm UTC](https://www.ruby-forum.com/t/using-request-user-agent-to-determine-if-someone-is-using-i/66299/6 "2006-08-26T12:16:59Z")

</div>

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
