【问题标题】:Rails routing: namespace nested in a scopeRails 路由:嵌套在范围内的命名空间
【发布时间】:2012-05-10 00:12:17
【问题描述】:

使用 Rails 3.2 我在 config/routes.rb 中有以下内容

scope "/:locale" do
    resource :users, :only => [:new, :create]

    namespace :admin do
        resources :specifications
    end
end

用户路线按预期工作,规范路线工作,除了索引。通过 GET 调用“/en/admin/specifications”会返回以下错误:

No route matches {:action=>"show", :controller=>"admin/specifications", :locale=>#<Specification id: 1, name: "Check-in", created_at: "2012-04-28 12:10:29", updated_at: "2012-04-28 12:10:29">}

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails namespaces scope url-routing


    【解决方案1】:

    尝试将其添加到您的应用程序控制器中:

    def default_url_options(options={})
      {:locale => I18n.locale}
    end
    

    它对我有用,我建议你阅读 I18n 指南的部分,在哪里解释如何set the locale from the URL params

    PS:欢迎来到 StackOverflow ;)

    【讨论】:

      猜你喜欢
      • 2011-11-07
      • 2012-07-05
      • 2015-03-19
      • 1970-01-01
      • 2018-03-15
      • 2016-07-22
      • 2013-10-09
      • 1970-01-01
      • 2017-11-09
      相关资源
      最近更新 更多