Created
February 21, 2009 16:47
-
-
Save vangberg/68085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| If only one of the text fields are filled in the params will look like this: | |
| {"foo" => "bar"} | |
| While it looks like this if both are filled in: | |
| {"foo" => ["bar", "baz"]} | |
| And really, in the first case it *should* be: | |
| {"foo" => ["bar"]} | |
| While there might be some debate over this, I think it's pretty natural: | |
| The code that handles the form data expects params["foo"] to be an array. | |
| With the current behaviour that code needs to check wether params["foo"] | |
| is an array or something else, and then act differently depending. If | |
| params["foo"] always is an array, the same piece of code handles it all. | |
| Less hassle. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'sinatra' | |
| get '/' do | |
| puts params.inspect | |
| haml :index | |
| end | |
| __END__ | |
| @@ index | |
| !!! | |
| %html | |
| %body | |
| %form{:action => '/', :method => 'GET'} | |
| %input{:type => 'text', :name => 'foo[]'} | |
| %input{:type => 'text', :name => 'foo[]'} | |
| %input{:type => 'submit'} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment