gpt4 book ai didi

ruby-on-rails - rails 上的 ruby 。 Unicode 路由

转载 作者:数据小太阳 更新时间:2023-10-29 06:58:19 27 4
gpt4 key购买 nike

是否可以在 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 routesmagazines GET /журналы(.:format) {:action=>"index", :controller=>"magazines"}

但是当我转到路径时,出现路由错误:

$ w3m http://localhost:3000/журналы...Routing ErrorNo route matches "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B"

这是服务器日志:

$ 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 +0400ActionController::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)

谢谢。

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 - rails 上的 ruby 。 Unicode 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3797389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com