(缺少)在新的 Rails 3 应用程序中支持 iPhone 的步骤
我缺少哪一步?返回到我的 iPhone 的视图来自 application.html.erb 和 index.html.erb
步骤 1:在 config/initializers/mime_types.rb 中取消注释 iPhone 的声明行:
Mime::Type.register_alias "text/html", :iphone
步骤 2:复制 app/views/layouts/application.html.erb 将其称为 application.iphone.erb (我喜欢将标题更改为特定于您的 iPhone 的内容,这样您就可以立即看到正确的正在使用布局)
<title>My iPhone Tasks</title>
第 3 步:在控制器中复制必要的视图文件,将它们命名为“index.iphone.erb”
第 4 步:决定是否坚持使用专门调用格式的 respond_to 块的 Rails 2 模型iPhone 或切换到使用 respond_with 调用的更 DRY 方法。这就是我所做的,呃尝试过;-)
步骤 4a:将 respond_to 块添加到控制器:
class TasksController < ApplicationController
respond_to :html, :iphone
步骤 4b:干燥你的方法,例如:
def index
@tasks = Task.all
respond_with (@tasks)
end
步骤 5:重新启动服务器并从 iPhone 上点击应用程序。
What step am I missing? The view being returned to my iPhone is coming from application.html.erb and index.html.erb
Step 1: In config/initializers/mime_types.rb uncomment the declaration line for the iPhone:
Mime::Type.register_alias "text/html", :iphone
Step 2: Make a copy of app/views/layouts/application.html.erb calling it application.iphone.erb (I like to change the title to something specific to your iPhone so you can see immediately that the correct layout is being used)
<title>My iPhone Tasks</title>
Step 3: Make copies of the necessary view files in your controllers, calling them things like index.iphone.erb
Step 4: Decide whether to stick with the Rails 2 model of respond_to blocks that specifically call out a format of iphone or switch to the more DRY approach that uses the respond_with call. That's what I've done, er tried ;-)
Step 4a: Add to your controller the respond_to block:
class TasksController < ApplicationController
respond_to :html, :iphone
Step 4b: DRY up your methods, such as:
def index
@tasks = Task.all
respond_with (@tasks)
end
Step 5: Restart your server and hit the app from your iPhone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须为您的移动 mime 类型编写一个响应程序,respond_with 才能正常工作。
在application_controller.rb中定义响应者:
You have to write a responder for your mobile mime type for respond_with to properly work.
Define the responder in application_controller.rb: