Skip to content

Instantly share code, notes, and snippets.

@donnior
Created January 10, 2012 12:49
Show Gist options
  • Save donnior/1588907 to your computer and use it in GitHub Desktop.
Save donnior/1588907 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jan 10, 2012.
    36 changes: 36 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #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