WhoDidThis
WhoDidThis

Reputation: 383

Scope of constraints in Rails 4 routes

Is it possible in Rails 4 to create a scope of constraints as described in here?

routes.rb

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

The error I'm getting is

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)>'

Upvotes: 2

Views: 2507

Answers (1)

WhoDidThis
WhoDidThis

Reputation: 383

Found it, format type must be in slashes:

routes.rb

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

Upvotes: 2

Related Questions