Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ahpook/1199036 to your computer and use it in GitHub Desktop.

Select an option

Save ahpook/1199036 to your computer and use it in GitHub Desktop.

Revisions

  1. ahpook revised this gist Sep 6, 2011. 1 changed file with 12 additions and 6 deletions.
    18 changes: 12 additions & 6 deletions sinatra-multiple-values-fail
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,12 @@
    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).
    # 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
    @@ -12,11 +18,11 @@ post '/lame' do
    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'
    __END__

    <!-- lame.erb -->
    @@ lame
    <form method="POST" action="/lame">
    <select name="select_multiple_values" multiple size="5">
    <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
  2. @randomcamel randomcamel revised this gist Sep 6, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sinatra-multiple-values-fail
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    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.
    the rack.request.query_string variable (but not the rack.request.params variable).

    get '/lame' do
    erb :lame
  3. @randomcamel randomcamel revised this gist Sep 6, 2011. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions sinatra-multiple-values-fail
    Original file line number Diff line number Diff line change
    @@ -2,18 +2,24 @@ Sinatra 1.2.6 doesn't appear to properly handle multiple values for a form param
    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.

    post '/lame/' do
    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>
    </form>
    <input type="submit">
    </form>
  4. @randomcamel randomcamel revised this gist Sep 6, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion sinatra-multiple-values-fail
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    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.
    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.

    post '/lame/' do
    puts params.inspect
  5. @randomcamel randomcamel created this gist Sep 6, 2011.
    17 changes: 17 additions & 0 deletions sinatra-multiple-values-fail
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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.

    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'

    <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>
    </form>