Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ahpook/1199036 to your computer and use it in GitHub Desktop.
Save ahpook/1199036 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).
# This comes straight outta rack so it's not actually sinatra's fault. It's also undocumented magic in the
# rack/utils.rb#normalize_params method.
require 'rubygems'
require 'sinatra'
get '/lame' do
erb :lame
end
post '/lame' do
puts params.inspect
puts request.inspect
puts params[:select_multiple_values]
end
__END__
@@ lame
<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