Skip to content

Instantly share code, notes, and snippets.

@randomcamel
Created September 6, 2011 20:21
Show Gist options
  • Save randomcamel/1198834 to your computer and use it in GitHub Desktop.
Save randomcamel/1198834 to your computer and use it in GitHub Desktop.
Sinatra failing to produce multiple param values
Sinatra 1.2.6 doesn't appear to properly handle multiple values for a form parameter. 'params[:my_param_name]'
only returns the last one supplied. I've verified that Chrome is sending the full list, and the list appears in
the rack.request.query_string variable (but not the rack.request.params variable).
get '/lame' do
erb :lame
end
post '/lame' do
puts params.inspect
puts request.inspect
puts params[:select_multiple_values]
end
# or use curl -X POST 'http://localhost:8000/lame/?select_multiple_values=oink&select_multiple_values=foo&select_multiple_values=bar'
<!-- lame.erb -->
<form method="POST" action="/lame">
<select name="select_multiple_values" multiple size="5">
<option value="First Option">Option 1
<option value="Second Option">Option 2
<option value="Third Option">Option 3
</select>
<input type="submit">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment