From fd6f9faadf039bdc1a1d22077f6f8daba195b6fb Mon Sep 17 00:00:00 2001 From: Chris Continanza Date: Tue, 12 Oct 2010 13:41:05 -0500 Subject: [PATCH 1/3] Only override :html requests --- lib/mobile_fu.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mobile_fu.rb b/lib/mobile_fu.rb index b3aac85..b12bf30 100644 --- a/lib/mobile_fu.rb +++ b/lib/mobile_fu.rb @@ -67,7 +67,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 +99,4 @@ def is_device?(type) end -ActionController::Base.send(:include, ActionController::MobileFu) \ No newline at end of file +ActionController::Base.send(:include, ActionController::MobileFu) From de1d0f76776b1bdd531faf78dd41681eabe971b2 Mon Sep 17 00:00:00 2001 From: Chris Continanza Date: Tue, 12 Oct 2010 14:19:50 -0500 Subject: [PATCH 2/3] Allow you to selectively apply mobile detection with before_filter --- README.rdoc | 19 +++++++++++++++++++ lib/mobile_fu.rb | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/README.rdoc b/README.rdoc index 36ae110..35249bd 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 enabled 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 b12bf30..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 From 30484e6c5445a16858c1ecd1e5ce6818f4336de3 Mon Sep 17 00:00:00 2001 From: Chris Continanza Date: Fri, 15 Oct 2010 18:17:00 -0500 Subject: [PATCH 3/3] fix wording --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 35249bd..9da20f2 100644 --- a/README.rdoc +++ b/README.rdoc @@ -39,7 +39,7 @@ 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 enabled the plugin with: +is mobile, you can enable the plugin with: class ApplicationController < ActionController::Base enable_mobile_fu