我缺少什么步骤?返回到我iPhone的视图来自application.html.erb和index.html.erb
步骤1:在config/iinitializers/meme_types.rb中,取消注释iPhone的声明行:
Mime::Type.register_alias "text/html", :iphone
步骤2:复制app/views/layouts/application.html.erb,称其为application.iphone.erb 步骤3:在控制器中复制必要的视图文件,称之为index.iphone.erb 步骤4:决定是坚持使用专门调用iphone格式的responsd_to块的Rails2模型,还是切换到使用responsd_with调用的更DRY方法。我就是这么做的,呃试过了;-) 步骤4a:将responsd_to块添加到控制器中: 步骤4b:干燥你的方法,例如: 步骤5:重新启动服务器,然后从iPhone上点击应用程序。<title>My iPhone Tasks</title>
class TasksController < ApplicationController
respond_to :html, :iphone
def index
@tasks = Task.all
respond_with (@tasks)
end
您必须为responsd_with的移动mime类型编写一个响应程序才能正常工作。
在application_controller.rb:中定义响应程序
def self.responder
MobileResponder
end
class MobileResponder < ActionController::Responder
def to_format
super
rescue ActionView::MissingTemplate => e
if request.format == "iphone"
navigation_behavior(e)
else
raise unless resourceful?
api_behavior(e)
end
end
end