Module: MobileNinja::ControllerAdditions::InstanceMethods

Defined in:
lib/mobile_ninja.rb

Overview

Instance Methods

Instance Method Summary collapse

Instance Method Details

#check_for_mobileObject



27
28
29
30
31
# File 'lib/mobile_ninja.rb', line 27

def check_for_mobile
  # the use of mobile request parameter should be for testing purpose only
  session[:mobile_override] = params[:mobile] if params[:mobile]
  prepare_for_mobile if mobile_device?
end

#mobile_device?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/mobile_ninja.rb', line 37

def mobile_device?
  if session[:mobile_override]
    !!session[:mobile_override].match(/^(true|t|yes|y|1)$/i)
  else
    # iPad is not considered as a mobile device
    (request.user_agent =~ /Mobile|webOS/) && (request.user_agent !~ /iPad/)
  end
end

#prepare_for_mobileObject



33
34
35
# File 'lib/mobile_ninja.rb', line 33

def prepare_for_mobile
  prepend_view_path Rails.root.join('app', 'views_mobile')
end