【问题标题】:rails translated paths examplerails 翻译路径示例
【发布时间】:2013-08-27 15:02:04
【问题描述】:

routes.rb

match "about/how_it_works" => "about#how_it_works", :as => "about_how_it_works", :via => :get
  match "about/we_are" => "about#we_are", :as => "about_we_are", :via => :get
  match "about/what_is" =>  "about#what_is", :as => "about_what_is", :via => :get

我阅读了this rails guide 并更改了我的代码。

新的routes.rb

scope(path_names: { about_we_are: 'translated-about-we-are', about_what_is: 'translated-about-what-is' }) do
  resources :about, path: 'translated-about'
end

但是当我输入 localhost:3000/about/translated-about-we-are 时,我遇到 no route matches 错误。你知道如何处理这个问题吗?

【问题讨论】:

    标签: ruby-on-rails routes


    【解决方案1】:

    由于您为资源 about 指定了 path,因此您的路径变为 translated-about/...。所以你需要使用:

    http://localhost:3000/translated-about/translated-about-we-are
    

    那么你不应该得到错误。

    您可以检查通过在您的应用程序目录中发出rake routes 生成的所有路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 2016-12-29
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多