iPhone on Rails


/ Published in: Ruby
Save to your folder(s)

A simple way to build iPhone specific interface with Rails


Copy this code and paste it in your HTML
  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

You need to login to post a comment.