sinatra/sinatra — Issue #406: Variables in routes not working
Author: leifg
Created: 2011-11-11 09:56:09+00:00
State: open

Hello everyone,

I'd like to make my routes configurable. Therefore I specified a prefix in the configuration and wanted to achieve something like this:

get "/#{settings.prefix}:id/"

But I didn't get it to work that way (undefined method `prefix' for Sinatra::Application:Class (NoMethodError)). I tried several other ways:

before do
@prefix = settings.prefix
end

get %r{#{@prefix}(\d+)} do |id|
puts "Params: #{id}"
end

(in this case the @prefix variable is empty)

Is there ANY way to achieve variables in routes?