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

encode nil IDs as nil #63

Merged
merged 2 commits into from
Oct 31, 2019
Merged

Conversation

fauxparse
Copy link
Contributor

@fauxparse fauxparse commented Aug 29, 2019

In "normal" Rails, the id (and hence the value of #to_param) is nil
for records that have not yet been persisted.

Previously, including the Hashid::Rails concern broke this behaviour,
raising an exception when Model.new.to_param was called. (Cases where
you might want to get the ID of a new model include serializing it over
a JSON API where the "edit" endpoint returns a new model instance if
one does not already exist.)

This change handles the above case by checking for nil in
model.hashid_encode.

fauxparse and others added 2 commits August 30, 2019 09:15
In "normal" rails, the `id` (and hence the value of `#to_param`) is nil
for records that have not yet been persisted.

Previously, including the `Hashid::Rails` concern broke this behaviour,
raising an exception when `Model.new.to_param` was called. (Cases where
you might want to get the ID of a new model include serializing it over
a JSON API where the "edit" endpoint returns a new model instance if
one does not already exist.)

This change handles the above case by checking for nil in
`model.hashid_encode`.
Copy link
Owner

@jcypret jcypret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense and has good spec coverage proving it out. Thanks for the PR!

@jcypret jcypret merged commit 1985f1c into jcypret:master Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants