ruby-on-rails - Rails 路由 : namespace nested in a scope

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

对于 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">}

我做错了什么?

最佳答案

尝试将此添加到您的应用程序 Controller 中:

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

它对我有用,我建议您阅读 I18n 指南的部分,其中解释了如何 set the locale from the URL params .

PS:欢迎来到 StackOverflow ;)

关于ruby-on-rails - Rails 路由 : namespace nested in a scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10381241/

相关文章:

ruby-on-rails - Ruby 用变量解析 DateTime

javascript - 更新 jQuery $(document).ready() 基本范围内的变量?

javascript - 范围变量在向用户弹出后更新,但不在某个位置

ruby-on-rails - 使用 RubyInstaller 1.9.1 RC2 后在 Windows 上启动 mongrel 时出错

ruby-on-rails - rails MVC 命名约定是否适用于复数形式为 "-ies"的单词(例如回复)?

ruby-on-rails - 命名空间模型中的 Rails 关联

c# - 数据库中的 Entity Framework 生成命名空间错误

javascript - 在全局变量中存储 getJSON 数据,但后来说它未定义

javascript - 使用 selectize.js 在下拉列表中仅显示三个输入

c# - 如何添加xml命名空间