当前位置:  开发笔记 > 后端 > 正文

Ruby on Rails.Unicode路由

如何解决《RubyonRails.Unicode路由》经验,为你挑选了1个好方法。

是否可以在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 routes
magazines GET /???????(.:format) {:action=>"index", :controller=>"magazines"}

但是当我走到路径时,我收到路由错误:

$ w3m http://localhost:3000/???????
...

Routing Error

No 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 +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)

谢谢.

Debian GNU/Linux 5.0.6;

Ruby 1.9.2;

Ruby on Rails 3.0.0.



1> raggi..:

相互关联,我认为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

推荐阅读
mobiledu2402852357
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有