Skip to content

Instantly share code, notes, and snippets.

@donnior
Created January 10, 2012 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donnior/1588907 to your computer and use it in GitHub Desktop.
Save donnior/1588907 to your computer and use it in GitHub Desktop.
add_iphone_view_support.rb
#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