如何让我的应用程序休息以支持手机
我现在要开发一个手机网站,既支持常见的html格式页面,又支持wml格式页面(因为现在手机上常用的浏览器可以查看html页面,而一些旧手机只支持wml)
第一步:
为wml页面注册内容类型 配置/初始化程序/mime_types.rb
Mime::Type.register_alias "text/vnd.wap.wml", :wml
第二: 为视图中的操作创建两种格式的页面:
class WelcomeController < ApplicationController
def index
@latest_on_sale_auctions = Auction.latest(15)
respond_to do |format|
format.html
format.wml
end
end
end
它在我访问时效果很好: http://localhost:3000/welcome 但得到:路由错误 没有路线与“/welcome.wml”与 {:method=>:get} 匹配 当我访问时:http://localhost:3000/welcome.wml
当我访问时它运行良好:http://localhost:3000/welcome?format=wml
my config/routes.rb like this:
ActionController::Routing::Routes.draw do |map|
map.root :controller => "welcome"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
我的rails版本是2.3。 5,请帮助我,我想要一个安静的应用程序,都支持html和wml。
I am now going to develop a mobile website both support common html format page and wml format page(Because now a usual web browser on mobile can view html page and some old mobiles only support wml )
First step:
register content type for wml page
config/initializers/mime_types.rb
Mime::Type.register_alias "text/vnd.wap.wml", :wml
Second:
Create two format page for an action in view:
class WelcomeController < ApplicationController
def index
@latest_on_sale_auctions = Auction.latest(15)
respond_to do |format|
format.html
format.wml
end
end
end
It works well as I visit:
http://localhost:3000/welcome
But got: Routing Error
No route matches "/welcome.wml" with {:method=>:get}
as I visit:http://localhost:3000/welcome.wml
and it works well as I visit:http://localhost:3000/welcome?format=wml
my config/routes.rb like this:
ActionController::Routing::Routes.draw do |map|
map.root :controller => "welcome"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
My rails version is 2.3.5,please help me, I want a restful app,both support html and wml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你很幸运! Railscasts 的一集刚刚发布了关于这个主题的内容:
http://railscasts.com/episodes/199 -移动设备
You're in luck! A Railscasts episode just came out about this very topic:
http://railscasts.com/episodes/199-mobile-devices