Module: IsItMobile::ForRails

Included in:
ActionController::Base
Defined in:
lib/rails/init.rb

Overview

When IsItMobile::ForRails is included in a controller, a before filter is added that will reset the request format to the value of base.mobile_format which defaults to :mobile. To change it to something else, simply add a line after the inclusion that says self.mobile_format = :handheld or whatever you’d like it to be.

It also exposes the request_is_from_mobile? method to the views if you don’t want to create multiple erb views for every page

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails/init.rb', line 15

def self.included(base)
  base.class_eval do
    include ::IsItMobile::ForRails::InstanceMethods
    
    class_inheritable_accessor :mobile_format
    self.mobile_format = :mobile

    before_filter :change_request_format_to_mobile, :if => :request_is_from_mobile?

    helper_method :request_is_from_mobile?, :mobile?
    IsItMobile::POPULAR_DEVICES.each do |device|
      helper_method "request_is_from_#{device}?".to_sym, "#{device}?".to_sym
    end
  end
end