2

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

路线.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)>'
4

1 回答 1

2

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

路线.rb

scope format: true, constraints: { format: /json/ } do
  get '/bar' => "bar#index_with_json"
end
于 2013-03-05T18:18:39.827 回答