Ruby on Rails.Unicode 路由 [英] Ruby on Rails. Unicode routes
问题描述
是否可以将 Unicode 字符串设置为 Rails 中的路径段?
我尝试以下操作:
<前><代码># app/controllers/magazines_controller.rbclass MagazinesController<前><代码># 编码:utf-8# 配置/路由.rbPublishingHouse::Application.routes.draw 做资源:杂志,:only => :index,:path => :журналы # Unicode 字符串被设置为路径的一部分结尾
<前>$ 耙路线杂志 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.1ActionController::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 做资源:杂志,:only =>:指数,:路径=>Rack::Utils.escape('журналы') # 一个Unicode字符串被设置为路径的一段结尾
Is it possible to set a Unicode string as a segment of a path in Rails?
I try the following:
# app/controllers/magazines_controller.rb
class MagazinesController < ApplicationController
def index
end
end
# encoding: utf-8
# config/routes.rb
PublishingHouse::Application.routes.draw do
resources :magazines,
:only => :index,
:path => :журналы # a Unicode string is set as a segment of the path
end
$ rake routes magazines GET /журналы(.:format) {:action=>"index", :controller=>"magazines"}
But when I go to the path I get the Routing error:
$ w3m http://localhost:3000/журналы ... Routing Error No route matches "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B"
Here's the server log:
$ rails s thin ... Started GET "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B" for 127.0.0.1 at 2010-09-26 13:35:00 +0400 ActionController::RoutingError (No route matches "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B"): Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
Thanks.
Debian GNU/Linux 5.0.6;
Ruby 1.9.2;
Ruby on Rails 3.0.0.
Intereting, I think Rails need a patch for this. I shall speak with someone from core about it later. In the meantime, the following should work:
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.Unicode 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!