Coder Social home page Coder Social logo

is_it_iphone's Introduction

is_it_iphone

AUTHOR:

Damon Danieli ([email protected])

FEATURES/PROBLEMS:

  • Fast & Lightweight
  • Simple: I'm not smart enough to make something complex

DESCRIPTION:

This gem was inspired by the IsItMobile gem done by Dave Myron.

The code to check for the iPhone user agent is from http://developer.apple.com. This doesn't have any dependencies.

  • in app/controllers/application.rb

    require 'is_it_iphone' class ApplicationController < ActionController::Base include IsItIPhone before_filter :adjust_format_for_iphone # Always show iPhone views end

You will have these functions:

iphone_user_agent?
  Returns true if the user agent is an iPhone.
  (as spec'ed on http://developer.apple.com)

iphone_request?
  Returns true if the request came from an iPhone.
  Override being an iPhone with ?format=xxxx in the URL.

adjust_format_for_iphone
  Call when you want to show iPhone views to iPhone users.
  Note: It is recommended by Apple that you default to showing 
  your "normal" html page to iPhone users and allow them to 
  choose if they want an iPhone version.

With Rails 2.0, you can use its multiview capabilities by simply adding this to your app:

  • in config/initializers/mime_types.rb

    Mime::Type.register_alias "text/html", :iphone

Then, just create your views using suffices of iphone.erb instead of html.erb:

index.iphone.erb
show.iphone.erb
etc.

Note: you will probably want to use a Web library specific for iPhone applications. FWIW, I use Dashcode (in the iPhone SDK) to write and debug the iPhone application and then integrate it with my Rails project.

REQUIREMENTS:

None

INSTALL:

sudo gem install is_it_iphone

NOTE! Dont't forget to add/uncomment line Mime::Type.register_alias "text/html", :iphone in RAILS_ROOT/config/initializers/mime_types.rb after gem being installed. Otherwise you'll get exception "undefined method `ref' for nil:NilClass" without backtrace.

LICENSE:

Copyright (c) 2008

MIT Licence

is_it_iphone's People

Contributors

osdrv avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.