views:

203

answers:

2

I'm trying to get this Sinatra GET request to work:

get '/:year/:month/:day/:slug' do

end

I know you can get one param to work with block parameters:

get '/:param' do |param|
  "Here it is: #{param}."
end

But how can I use multiple block parameters with the first code block? I'm open to other methods.

A: 

Forgive my ignorance of Sinatra, but shouldn't this set named parameters like Rails map.connect?:

get '/:year/:month/:day/:slug

Now the parameters should be accessible in the params hash:

params = { :year => "foo", :month => "bar", :day => "baz", :slug => "etc" }
zetetic
+1  A: 

Multiple placeholders are stored in params as Hash.

# Request to /2009/10/20/post.html

get '/:year/:month/:day/:slug' do
  params[:year]  # => 2009
  params[:month] # => 10
  params[:day]   # => 20
  params[:post]  # => post.html
end
Simone Carletti