Reputation: 2961
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.
Upvotes: 4
Views: 2915
Reputation: 176422
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
Upvotes: 2
Reputation: 47548
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" }
Upvotes: 0