【问题标题】:Ruby on Rails. Unicode routesRuby on Rails。 Unicode 路由
【发布时间】:2011-04-17 09:04:52
【问题描述】:

是否可以在 Rails 中将 Unicode 字符串设置为路径的一部分?

我尝试以下方法:

# 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 路线 杂志 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 年 9 月 26 日 13:35:00 +0400 开始为 127.0.0.1 获取“/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B” 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;

红宝石 1.9.2;

Ruby on Rails 3.0.0。

【问题讨论】:

    标签: ruby-on-rails ruby unicode routes


    【解决方案1】:

    有趣,我认为 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
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    • 2018-12-28
    • 2011-05-11
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多