Power outlets in foreign lands… Channel 4 + 1: The brits way of dealing with time shifting
Oct 01

Rails 2.0 and the iPhone

Tech Add comments

Rails is making it simpler to implement an iPhone specific site using a fake mime-type:

# should go in config/initializers/mime_types.rb
Mime.register_alias "text/html", :iphone

class ApplicationController < ActionController::Base
before_filter :adjust_format_for_iphone

private
def adjust_format_for_iphone
if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod)/]
request.format = :iphone
end
end
end

class PostsController < ApplicationController
def index
respond_to do |format|
format.html   # renders index.html.erb
format.iphone # renders index.iphone.erb
end
end
end

There are plenty of other nice RESTie features too.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)