cause rails to correctly place optional path parameter booleans #42283
Previously, if you specify a url parameter that is part of the path as false it would include that part of the path as parameter for example:
this is not the case for empty string,
this is due to a quark in how path parameters get removed from the parameters.
we where doing
After this change,
The text was updated successfully, but these errors were encountered:
@HParker Thank you for your patch!
This is interesting because we're changing the behavior and some apps may be indirectly depending upon that.
What if you had an optional parameter that you expected to be a boolean?
Correct me if I'm wrong but the current behavior would still pass that parameter as
Thanks for looking at it @zzak!
Yeah, that is a good point. Until reading your comment I didn't know this was possible, but you can have a route like,
I updated my branch to make
This still prevents adding the parameter at the end of the url and makes behavior more consistent.
previously, if you specify a url parameter that is part of the path as false it would include that part of the path as parameter at the end of the url instead of in the path for example: `get "(/optional/:optional_id)/things" => "foo#foo", as: :things` `things_path(optional_id: false) # => /things?optional_id=false` this is not the case for empty string, `things_path(optional_id: '') # => "/things" this is due to a quark in how path parameters get removed from the parameters. we where doing `(paramter || recall).nil?` which returns nil if both values are nil however it also return nil if one value is false and the other value is nil. i.e. `(false || nil).nil # => nil` which is confusing. After this change, `true` and `false` will be treated the same when used as optional path parameters. meaning now, ``` get '(this/:my_bool)/that' as: :that that_path(my_bool: true) # => `/this/true/that` that_path(my_bool: false) # => `/this/false/that` ``` fixes: rails#42280 Co-authored-by: Ryuta Kamizono <email@example.com>