advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
Rate this item | 0 users have rated this item.
Email this articleEmail this article
 
iPhone Web Development with Ruby on Rails
Leverage the tremendous buzz surrounding the iPhone by customizing your web site with CSS and Ruby on Rails. 

 
advertisement
pple's iPhone has taken the nation by storm. An alleged half million moved from the shelves into people’s pockets in the first weekend it went on sale. Safari, the iPhone's native browser, claims to bring full featured browsing to the mobile device. You'll learn, over the course of this article, more than a few tricks that will help your website stand out on the iPhone. Knowledge of Ruby is not required to learn from this article as it relies heavily on Cascading Style Sheets and JavaScript to work its magic. You should be able to apply the tricks you'll learn here anywhere you'd use JavaScript or CSS. This article will not teach you everything you need to know about web development with Ruby on Rails, it will simply point out where the iPhone's browser differs from an ordinary one. Add up all these custom tweaks and you should have the tools you need to take your web site mobile.

For a primer on Ruby on Rails, take a look at the Related Resources connected to this article.


What You Need
An iPhone, or iPhony (iPhone browser emulator), a simple Ruby project over which you have control, and boundless imagination.

Recognizing the iPhone
There are several different ways to detect if one of your visitors is hitting your page from an iPhone. Most of them rely on temporary "hacks" for assuming that safari is the only browser that will correctly accept "max-device-width" parameters. Since Ruby is all about simplicity, you should strive for a solution that is low in maintainability. Here’s the simple Ruby way of detecting the existence of the iPhone:


	<%= if request.user_agent.include?("iPhone") then 
		render :partial => 'foriphoneonly' 
	end %>
Let's go over this code step-by-step:
  1. The code looks for "iPhone" within the user agent string. The full user iPhone UAString looks something like this:
    
    Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ 
    (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"
    
  2. When the iPhone is detected on the connection, the Rails application renders the partial 'foriphoneonly' exclusively for the iPhone. This trick allows you to have one URL for your web site; iPhone users will see one interface while Firefox, Safari, and IE browsers will see something different. There has been some debate on the merits of blocking iPhone specific content from Firefox and IE users but this decision is probably best left to your business department.
To get started right away, simply create a style sheet exclusively for the iPhone. You can specify specific media type declarations to focus our CSS to appear only on iPhones:

<!--[if !IE]>-->
<link media="only screen and (max-device-width: 480px)"
  href="iPhone.css" type="text/css" rel="stylesheet" />
<!--<![endif]-->
You have to special case the if statement so that IE will render the CSS correct and process the media type declaration.

  Next Page: Orientation, Orientation, Orientation
Page 1: IntroductionPage 3: iPhone Orientation in Ruby on Rails
Page 2: Orientation, Orientation, OrientationPage 4: Preventing the Zoom
Untitled
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES