Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix and Feature Addition #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
11 changes: 9 additions & 2 deletions lib/mobile_fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -99,4 +106,4 @@ def is_device?(type)

end

ActionController::Base.send(:include, ActionController::MobileFu)
ActionController::Base.send(:include, ActionController::MobileFu)