Multiple block parameters with Sinatra

I am trying to get this Sinatra GET request to work:

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

I know that you can get one parameter for working with block parameters:

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

But how can I use several block parameters with the first block of code? I am open to other methods.

+4
source share
2 answers

Several placeholders are stored in params as a 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 
+2
source

Forgive my ignorance of Sinatra, but should this not be given parameters such as Rails map.connect ?:

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

Parameters should now be available in the params hash:

 params = { :year => "foo", :month => "bar", :day => "baz", :slug => "etc" } 
0
source

All Articles