diff --git a/README.rdoc b/README.rdoc index 36ae110..9da20f2 100644 --- a/README.rdoc +++ b/README.rdoc @@ -38,6 +38,25 @@ Then add the line below to config/initializers/mime_types.rb Mime::Type.register_alias "text/html", :mobile +If you don't want EVERY request to automatically be converted to :mobile if the device +is mobile, you can enable the plugin with: + + class ApplicationController < ActionController::Base + enable_mobile_fu + end + +And then in the controller that has mobile views you do: + + class WhateverController < ApplicationController + before_filter :set_mobile_format + end + +If you want "test mode", or to always see the mobile view use: + + class WhateverController < ApplicationController + before_filter :force_mobile_format + end + I recommend that you setup a before_filter that will redirect to a specific page depending on whether or not it is a mobile request. How can you check this? diff --git a/lib/mobile_fu.rb b/lib/mobile_fu.rb index b3aac85..ba6d6b6 100644 --- a/lib/mobile_fu.rb +++ b/lib/mobile_fu.rb @@ -40,6 +40,13 @@ def has_mobile_fu(test_mode = false) helper_method :in_mobile_view? helper_method :is_device? end + + def enable_mobile_fu + include ActionController::MobileFu::InstanceMethods + helper_method :is_mobile_device? + helper_method :in_mobile_view? + helper_method :is_device? + end def is_mobile_device? @@is_mobile_device @@ -67,7 +74,7 @@ def force_mobile_format # the user has opted to use either the 'Standard' view or 'Mobile' view. def set_mobile_format - if is_mobile_device? && !request.xhr? + if request.format.html? && is_mobile_device? && !request.xhr? request.format = session[:mobile_view] == false ? :html : :mobile session[:mobile_view] = true if session[:mobile_view].nil? end @@ -99,4 +106,4 @@ def is_device?(type) end -ActionController::Base.send(:include, ActionController::MobileFu) \ No newline at end of file +ActionController::Base.send(:include, ActionController::MobileFu)