Created
January 10, 2012 12:49
-
-
Save donnior/1588907 to your computer and use it in GitHub Desktop.
add_iphone_view_support.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/mime_types.rb | |
Mime::Type.register_alias "text/html", :iphone | |
#Make a copy of app/views/layouts/application.html.erb calling it application.iphone.erb | |
#Make copies of the necessary view files in your controllers, calling them things like index.iphone.erb | |
#in Controller | |
respond_to :html, :iphone | |
#in ApplicationController | |
def self.responder | |
MobileResponder | |
end | |
class MobileResponder < ActionController::Responder | |
def to_format | |
super | |
rescue ActionView::MissingTemplate => e | |
if request.format == "iphone" | |
navigation_behavior(e) | |
else | |
raise unless resourceful? | |
api_behavior(e) | |
end | |
end | |
end | |
#in ApplicationController, set iphone format in before_filter。。。!!Maybe not need? | |
before_filter :check_format | |
def check_format | |
if request.env["HTTP_USER_AGENT"].downcase.match(/iphone/) | |
request.format = "iphone" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment