Answer the question
In order to leave comments, you need to log in
How to correctly set a route with a request in Sinatra?
You need to implement something like this:
If you access /items
it, it shows the total number of products.
If you access /items?car,toys
it, it shows the total number + number of toys + number of cars.
I assume that in the view you can do something like that (if the request contains /items?car,toys
)
<% unless params[:name].empty? %>
<%= ... %>
<% end %>
get '/items?:name' do
erb :items
end
Answer the question
In order to leave comments, you need to log in
# GET /items/car,toys
get '/items/:name' do |name|
p name # car,toys
#...
end
# GET /items
get '/items' do
p request.query_string # ""
end
# GET /items?car,toys
get '/items' do
p request.query_string # "car,toys"
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question