是否可以在Rails 4中创建约束范围,如here?
中所述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)>'
答案 0 :(得分:2)
找到它,格式类型必须是斜杠:
scope format: true, constraints: { format: /json/ } do
get '/bar' => "bar#index_with_json"
end