Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cause rails to correctly place optional path parameter booleans #42283

Merged
merged 1 commit into from Jun 1, 2021

Commits on May 28, 2021

  1. cause rails to correctly place optional path parameters

    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 <kamipo@gmail.com>
    HParker and kamipo committed May 28, 2021
    Copy the full SHA
    98ed240 View commit details
    Browse the repository at this point in the history