fooledbyprimes
fooledbyprimes

Reputation: 1019

How to specify json format for Sinatra route with named parameter?

How do I add ".json" to a Sinatra route which includes a named parameter such as get '/view/:name'
?

I thought get '/view/:name.json' might work but I get an "Unable to access path /view/name.json" exception.

Upvotes: 1

Views: 1452

Answers (2)

Samy Dindane
Samy Dindane

Reputation: 18716

This code works perfectly:

get '/hello/:name.json' do
  "Hello #{params[:name]}"
end

=> /hello/samy.json outputs "Hello samy"

Please show the complete stack trace of your exception.

Upvotes: 1

Related Questions