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

Use find instead of find by id #1831

Merged
merged 7 commits into from
Jan 24, 2019
Merged

Conversation

microweb10
Copy link
Collaborator

Objectives

  • Use find(id) instead of find_by(id: id). It's preferable to raise a 404 HTML error than any other unexpected/unknown Exception.

  • Add the methods find_by_slug_or_id and find_by_slug_or_id! to the module Sluggable to make it easier to add these methods other models.

Does this PR need a Backport to CONSUL?

The following commits can be backported now:

  • Use correct param in controller 43be16e
  • Remove unused before_action 0108b25
  • Use find instead of find_by_id fdc298d
  • Add method find_by_slug_or_id to Sluggable module b54014b
  • Add method find_by_slug_or_id! to Sluggable module b2ba489

The last commit 1b6c1ee, it would be nice to be able to find_by_slug also in CONSUL
But, we will probably do it in a future PR, we will have to include at least this other PR #520

There were some custom routes created using the param[:id] but the
Rails routes use the param[:budget_id] by default, so the same
controller could be asked for different param keys.
This method will raise an exception if resource is not found when
trying to call score_action on nil.
Prefer to raise a 404 HTML NotFound error instead.
Make it easier to find by slug or id for sluggable models. Will return
nil if resource is not found.
Make it easier to find by slug or id for sluggable models. It will
raise a 404 HTML Not found error if the resource is not found.
Better raise a 404 HTML NotFound exception than any other unexpected error.
@microweb10 microweb10 force-pushed the use_find_instead_of_find_by_id branch from 1b6c1ee to 1f4272b Compare January 17, 2019 10:07
@microweb10 microweb10 changed the title Use find instead of find by Use find instead of find by id Jan 17, 2019
@microweb10 microweb10 merged commit 9a1b040 into master Jan 24, 2019
@microweb10 microweb10 deleted the use_find_instead_of_find_by_id branch January 24, 2019 17:23
@microweb10 microweb10 moved this from Review to Done in Roadmap Jan 24, 2019
@javierm javierm mentioned this pull request Feb 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants