Posted By

ctran on 08/18/07


Tagged

iphone


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

webstic
umang_nine
kennyvb


iPhone on Rails


 / Published in: Ruby
 

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ctran on August 18, 2007
Posted By: ChristopherA on October 16, 2007

This will fail with non-iPhone devices with Safari such as the iPod Touch -- you should instead check for 'mobile' and 'safari'. -- Christopher Allen www.iPhoneWebDev.com

You need to login to post a comment.