norman / friendly_id

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
http://norman.github.io/friendly_id/
MIT License
6.13k stars 589 forks source link

`allow_nil: true` on the find method does not work as expected. #1001

Closed xxx closed 1 year ago

xxx commented 1 year ago

Hi,

From the readme, I expect that I should be able to do something like MyModel.friendly.find('nonexistent-slug', allow_nil: true) and have the call return nil without raising an exception, but when I make this call, I instead get Couldn't find all MyModels with 'id': (nonexistent_slug, {:allow_nil=>true}) (found 0 results, but was looking for 2), as if the args are being splatted into a single array of IDs to find.

MyModel.friendly.find(id) without allow_nil works as expected.

I'm wondering if this is something to do with the change in how keyword args are handled between Ruby 2 and 3.

FriendlyId: 5.4.2 Ruby: 3.1.2p20 Rails: 7.0.4

andrewcmyk commented 1 year ago

It's not in 5.4.2: https://github.com/norman/friendly_id/blob/master/Changelog.md

parndt commented 1 year ago

Apologies, this is not released yet.

parndt commented 1 year ago

Version 5.5.0 pushed @xxx please can you try that version? 😄

xxx commented 1 year ago

@parndt 5.5.0 is working great. thanks!

dchacke commented 8 months ago

You may want to update the Readme accordingly and prompt users to install ~> 5.5.0.

parndt commented 8 months ago

thanks @dchacke that's good advice 🚀 - do you happen to have any capacity to open a pull request that makes that change please? Or even if you are able to add it to #1023 ?

dchacke commented 8 months ago

yea done