【问题标题】:Scope of constraints in Rails 4 routesRails 4 路线中的约束范围
【发布时间】:2013-03-05 16:29:46
【问题描述】:

是否可以在 Rails 4 中创建here 中描述的约束范围?

routes.rb

scope format: true, constraints: { format: 'json' } do
  get '/bar' => "bar#index_with_json"
end

我得到的错误是

NoMethodError (undefined method 'source' for "json":String):
  config/routes.rb:17:in `block (2 levels) in <top (required)>'
  config/routes.rb:16:in `block in <top (required)>'
  config/routes.rb:1:in `<top (required)>'

【问题讨论】:

    标签: routes ruby-on-rails-4


    【解决方案1】:

    找到了,格式类型必须是斜杠:

    routes.rb

    scope format: true, constraints: { format: /json/ } do
      get '/bar' => "bar#index_with_json"
    end
    

    【讨论】:

    猜你喜欢
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 2012-10-02
    • 2013-04-06
    • 2017-11-02
    • 2016-07-11
    • 2014-02-06
    相关资源
    最近更新 更多