2

I would like to allow only mobile devices on my web site, such as blackberry, iPod-touch, iPhone, Android, etc.

How do I ensure that only those devices get onto my website, and that other users are redirected to a custom "no-access" page?

Is there an easy way using Ruby on Rails to make this happen?

Jay Godse
  • 15,163
  • 16
  • 84
  • 131
  • 1
    The server side can know the kind of device that makes a request by reading the headers. But I won't trust the headers too much, as they can be modified. If security is a real need, don't trust that information. – Nerian May 26 '11 at 17:04
  • @Nerian - I won't be able to stop somebody like that, nor do I care. I just don't want to create a separate UI for average non-mobile users. – Jay Godse May 26 '11 at 17:10
  • But I think those users would rather see a version not optimised for their platform than nothing at all. – Nerian May 26 '11 at 18:31

1 Answers1

3

You want to pull out a request header called "User-Agent" and see if it matches any of the devices you've stated. If not then redirect to the appropriate page. Yes, this can be done with Ruby on Rails.

jconlin
  • 3,806
  • 6
  • 31
  • 32
  • See this question for Ruby on Rails User-Agent detection http://stackoverflow.com/questions/4707400/rails-browser-detection-methods – Mark May 26 '11 at 17:16
  • Ahh...of course. The user agent. I dug around a bit. Between http://stackoverflow.com/questions/233802/rails-detecting-user-agent-works-in-development-but-not-production and http://asciicasts.com/episodes/151-rack-middleware, and http://www.developershome.com/wap/detection/detection.asp?page=userAgentHeader I think I should be able to cobble together a solution. – Jay Godse May 26 '11 at 17:23