A
A
Andrey2017-01-12 13:49:48
ruby
Andrey, 2017-01-12 13:49:48

How to correctly set a route with a request in Sinatra?

You need to implement something like this:
If you access /itemsit, it shows the total number of products.
If you access /items?car,toysit, 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 %>

in the controller how to register?
get '/items?:name' do
  erb :items
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Bordenyuk, 2017-01-12
@HighQuality

# 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 question

Ask a Question

731 491 924 answers to any question