Module: ActionController::MobileFu::ClassMethods

Defined in:
lib/mobile-fu.rb

Instance Method Summary collapse

Instance Method Details

#has_mobile_fu(set_request_format = true) ⇒ Object

Add this to one of your controllers to use MobileFu.

class ApplicationController < ActionController::Base
  has_mobile_fu
end

If you don’t want mobile_fu to set the request format automatically, you can pass false here.

class ApplicationController < ActionController::Base
  has_mobile_fu false
end


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mobile-fu.rb', line 55

def has_mobile_fu(set_request_format = true)
  include ActionController::MobileFu::InstanceMethods

  before_filter :set_request_format if set_request_format

  helper_method :is_mobile_device?
  helper_method :is_tablet_device?
  helper_method :in_mobile_view?
  helper_method :in_tablet_view?
  helper_method :is_device?
  helper_method :mobile_device
end

#has_mobile_fu_for(*actions) ⇒ Object

Add this to your controllers to only let those actions use the mobile format this method has priority over the #has_no_mobile_fu_for

class AwesomeController < ApplicationController
  has_mobile_fu_for :index

  def index
    # Mobile format will be set as normal here if user is on a mobile device
  end

  def show
    # Mobile format will not be set, even if user is on a mobile device
  end
end


97
98
99
# File 'lib/mobile-fu.rb', line 97

def has_mobile_fu_for(*actions)
  @mobile_include_actions = actions
end

#has_no_mobile_fu_for(*actions) ⇒ Object

Add this to your controllers to prevent the mobile format from being set for specific actions

class AwesomeController < ApplicationController
  has_no_mobile_fu_for :index

  def index
    # Mobile format will not be set, even if user is on a mobile device
  end

  def show
    # Mobile format will be set as normal here if user is on a mobile device
  end
end


80
81
82
# File 'lib/mobile-fu.rb', line 80

def has_no_mobile_fu_for(*actions)
  @mobile_exempt_actions = actions
end