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 #3580

Merged
merged 5 commits into from
Jun 5, 2019
Merged

Use find instead of find by #3580

merged 5 commits into from
Jun 5, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Jun 3, 2019

References

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.

bertocq and others added 4 commits June 3, 2019 16:54
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.
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.
@javierm javierm self-assigned this Jun 3, 2019
spec/features/budgets/results_spec.rb Outdated Show resolved Hide resolved
@@ -40,7 +87,7 @@
investments.each do |investment|
within("#budget-investments") do
expect(page).to have_content investment.title
expect(page).to have_css("a[href='#{budget_investment_path(budget_id: budget.id, id: investment.id)}']", text: investment.title)
expect(page).to have_css("a[href='#{budget_investment_path(budget, id: investment.id)}']", text: investment.title)

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [122/110] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

Better raise a 404 HTML NotFound exception than any other unexpected error.
@javierm javierm force-pushed the use_find_instead_of_find_by_id branch from 4cf0148 to b122302 Compare June 3, 2019 15:54
@javierm javierm merged commit 81b6734 into master Jun 5, 2019
@javierm javierm deleted the use_find_instead_of_find_by_id branch June 5, 2019 17:04
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

5 participants