denniss
denniss

Reputation: 17629

sinatra routes first path param is a number

I want to be able to match a route that looks something like

/2/monkey/session

I have the following in sinatra but

/:version_number/:name/session

And I keep getting the Sinatra doesn’t know this ditty. Anyone knows a way to getting this to work so that I can have params[:version_number] and params[:name] matched.

Upvotes: 0

Views: 197

Answers (1)

labocho
labocho

Reputation: 231

I wrote the code below (Ruby 2.0.0 / Sinatra 1.4.3).

require "sinatra"

get "/:version_number/:name/session" do
  params.inspect
end

The response seems like correctly.

{"splat"=>[], "captures"=>["2", "monkey"], "version_number"=>"2", "name"=>"monkey"}

Why don't you check HTTP method or comment out other code?

Upvotes: 1

Related Questions