Module: Mobylette::RespondToMobileRequests::ClassMethods
- Defined in:
- lib/mobylette/respond_to_mobile_requests.rb
Instance Method Summary collapse
-
#mobylette_config {|self.mobylette_options| ... } ⇒ Object
This method enables the controller do handle mobile requests.
Instance Method Details
#mobylette_config {|self.mobylette_options| ... } ⇒ Object
This method enables the controller do handle mobile requests
You must add this to every controller you want to respond differently to mobile devices, or make it application wide calling it from the ApplicationController
Possible options:
-
fall_back: :html
You may pass a fall_back option to the method, it will force the render to look for that other format, in case there is not a .mobile file for the view. By default, it will fall back to the html format. If you don't want fall back at all, pass fall_back: false -
skip_xhr_requests: true/false
By default this is set to true. When a xhr request enters in, it will skip the mobile verification. This will let your ajax calls to work as intended. You may disable this (actually you will have to) if you are using JQuery Mobile, or other js framework that uses ajax. To disable, set skip_xhr_requests: false -
mobile_user_agents: proc { /user_agents_match/ }
If you want to restrict the user agents that will be considered mobile devices, you can send a custom proc/object that returns the matching regex you wish. -
devices: /device_reg/, device2_name: /device2_reg/, …
You may register devices for custom behavior by device. Once a device is registered you may call the helper request_device?(device_symb) to see if the request comes from that device or not. By default :iphone, :ipad, :ios and :android are already registered. -
skip_user_agents: [:ipad, :android]
Don't consider these user agents mobile devices.
Example Usage:
class ApplicationController...
include Mobylette::RespondToMobileRequests
...
mobylette_config do |config|
config[:fall_back] = :html
config[:skip_xhr_requests] = false
config[:mobile_user_agents] = proc { %r{iphone|android}i }
config[:devices] = {cool_phone: %r{cool\s+phone} }
end
...
end
94 95 96 97 98 |
# File 'lib/mobylette/respond_to_mobile_requests.rb', line 94 def mobylette_config yield(self.) configure_fallback_resolver(self.) Mobylette.devices.register(self.[:devices]) if self.[:devices] end |