Module: MobileFu::ActionController::InstanceMethods

Defined in:
lib/mobile_fu/controller_methods.rb

Instance Method Summary collapse

Instance Method Details

#force_mobile_formatObject

Forces the request format to be :mobile



49
50
51
52
53
54
# File 'lib/mobile_fu/controller_methods.rb', line 49

def force_mobile_format
  unless request.xhr?
    session[:mobile_view] ||= true
    request.format = :mobile
  end
end

#in_mobile_view?Boolean

Returns either true or false depending on whether or not the format of the request is either :mobile or not.

Returns:

  • (Boolean)


65
66
67
# File 'lib/mobile_fu/controller_methods.rb', line 65

def in_mobile_view?
  request.format.to_sym == :mobile
end

#is_device?(type) ⇒ Boolean

Can check for a specific user agent e.g., is_device?(‘iphone’) or is_device?(:mobileexplorer)

Returns:

  • (Boolean)


77
78
79
# File 'lib/mobile_fu/controller_methods.rb', line 77

def is_device?(type)
  request.user_agent.to_s.downcase.include?(type.to_s.downcase)
end

#is_mobile_device?Boolean

Returns either true or false depending on whether or not the user agent of the device making the request is matched to a device in our regex.

Returns:

  • (Boolean)


71
72
73
# File 'lib/mobile_fu/controller_methods.rb', line 71

def is_mobile_device?
  !!(request.user_agent.to_s.downcase =~ Regexp.new(MobileFu::ActionController::MOBILE_USER_AGENTS))
end

#set_mobile_formatObject

Determines the request format based on whether the device is mobile or if the user has opted to use either the ‘Standard’ view or ‘Mobile’ view.



58
59
60
61
# File 'lib/mobile_fu/controller_methods.rb', line 58

def set_mobile_format
  session[:mobile_view] ||= is_mobile_device? ? true : false
  request.format = :mobile if session[:mobile_view] and request.format.html? and not request.xhr?
end