A simple way for Rails 3 to know if a visitor is on a mobile device.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
Gemfile
README.md
Rakefile
mobilized.gemspec

README.md

Mobilized

Installation

Add this to your Gemfile:

gem 'mobilized'

and then run:

bundle install

Usage

Controllers

mobilize all controllers:

class ApplicationController < ActionController::Base
  mobilized
end

mobilize a single controller:

class BlogsController < ApplicationController
  mobilized
end

this runs a before filter to set session[:is_mobile] to true or false

in your controller you can now use a couple of methods

is_mobile? => (true|false)

is_device?('ipad') => (true|false)

Views

a couple helper methods are also exposed to the views:

is_mobile? => (true|false)

is_device?('ipad') => (true|false)

Credits

Copyright 2011 by Jon Buda, sponsored by One Design Company. It is based partly on mobile-fu. Released under the MIT License.