Sunday, September 23, 2007

iphone on rails

A simple way to build iPhone specific interface with Rails

  1. class ApplicationController < ActionController::Base  
  2.   exempt_from_layout('iphone_html.erb')  
  3.     
  4.   before_filter :check_iphone  
  5.     
  6.   protected  
  7.   def iphone?  
  8.     request.user_agent.include?('iPhone')  
  9.   end  
  10.     
  11.   def check_iphone  
  12.     if iphone?  
  13.       request.parameters[:format] = 'iphone_html'  
  14.     end  
  15.   end  
  16. end  
  17.   
  18. class DashboardController < ApplicationController  
  19.   def index  
  20.     @top_movies = Movie.top_movies  
  21.     @movie = @top_movies.first  
  22.       
  23.     respond_to do |format|  
  24.       format.html # index.html.erb  
  25.       format.iphone_html #index.iphone_html.erb  
  26.     end  
  27.   end  
  28. end  

4 comments:

  1. huh nice,
    only what we need is to have iphone in israel :)

    400$ on ebay, unlocked for any gsm

    ReplyDelete
  2. What you really want to check for here is mobile safari, not the iPhone as such. Mobile safari is used on both the iPhone and the iPod touch.

    Details are here.

    ReplyDelete
  3. We all know Apple iPhone is very rich in multimedia features including Internet capabilities... and of course the price isn't affordable to the average people...

    So if you own this Gadget I think it's better to have an extra care specially the screen, it needs Incase iPhone Slider Case to protect your iPhone from unwanted scratch.

    This is only an advice... don't think it seriously if you don't want.

    Peace!

    ReplyDelete
  4. That's right.
    i don't really think it's too expensive, but still, it is one of the best things i purchased.

    ReplyDelete

Tell me what you think