How to send list value in Ruby Sinatra?
I have a simple form where there is a list:
<form method ="post" action ="">
<select>Select subject
<option value="1">Maths</option>
<option value="2">Science</option>
</select>
<input type="submit" name="Submit" />
My question is, if I select the option Maths, I would like the value to be sent eg /1. What should be written in 开发者_StackOverflow社区action? How should the route be written ?
get '' do
end
Your route could look something like this:
post '/subject' do
@subject = params[:subject]
# do whatever you want now
end
But you would need to give your select
tag a name and your form
an action:
<form method="post" action="/subject">
<select name="subject">
<!-- etc etc -->
Also have a look at related questions.
we tend to look at queries as GETs (makes sense, it is after all retrieving information) rather than a POST which (doesn't actually change data) yet responds with a result page
a common (gnarly) pattern we often see is to rewrite (in js or redirect) to the form
GET '/search/:q1/and/:q2' do // result of search filtered by q1 and q2 end
which is also quite neat
精彩评论