1

我现在要开发一个手机网站,既支持普通的html格式页面,也支持wml格式的页面(因为现在手机上普通的网络浏览器可以查看html页面,而一些旧手机只支持wml)

第一步:

注册 wml 页面的内容类型 config/initializers/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 /欢迎.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。

4

1 回答 1

1

你很幸运!Railscasts 的一集刚刚发布了关于这个主题的内容:

http://railscasts.com/episodes/199-mobile-devices

于 2010-02-06T19:02:33.907 回答