是否可以将 Unicode 字符串设置为 Rails 中的路径段?
我尝试以下操作:
# app/controllers/magazines_controller.rbclass MagazinesController < ApplicationController def index endend
# encoding: utf-8# config/routes.rbPublishingHouse::Application.routes.draw do resources :magazines, :only => :index, :path => :журналы # a Unicode string is set as a segment of the pathend
$ rake 路线
杂志 GET/журналы(.:format) {:action=>"index", :controller=>"magazines"}
但是当我进入路径时,出现路由错误:
$ w3m http://localhost:3000/журналы
...
路由错误
没有路由匹配“/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B”
这是服务器日志:
$ rails 很薄
...
在 2010-09-26 13:35:00 +0400 开始 GET "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B"for 127.0.0.1
ActionController::RoutingError(没有路由匹配“/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B”):
在救援/布局中渲染/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb (1.2ms)
谢谢。
Debian GNU/Linux 5.0.6;
ruby 1.9.2;
Ruby on Rails 3.0.0。
最佳答案
有趣的是,我认为 Rails 需要一个补丁来解决这个问题。稍后我会和核心的人谈谈这件事。同时,以下应该起作用:
PublishingHouse::Application.routes.draw do
resources :magazines,
:only => :index,
:path => Rack::Utils.escape('журналы') # a Unicode string is set as a segment of the path
end
关于ruby-on-rails - Ruby on Rails。 Unicode 路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3797389/