Skip to content
  • Adam Hess's avatar
    98ed2406
    cause rails to correctly place optional path parameters · 98ed2406
    Adam Hess authored
    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: https://github.com/rails/rails/issues/42280
    
    
    
    Co-authored-by: default avatarRyuta Kamizono <kamipo@gmail.com>
    98ed2406
    cause rails to correctly place optional path parameters
    Adam Hess authored
    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: https://github.com/rails/rails/issues/42280
    
    
    
    Co-authored-by: default avatarRyuta Kamizono <kamipo@gmail.com>
Loading