Multiple Block Parameters with Sinatra
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 开发者_StackOverflow中文版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.
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
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" }
精彩评论