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 に答える