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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add method find_by_slug_or_id! to Sluggable module
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.
  • Loading branch information
microweb10 authored and javierm committed Jun 3, 2019
commit 22076dd95c1dfab462119bb028f11e116e9a6b1b
4 changes: 4 additions & 0 deletions app/models/concerns/sluggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module Sluggable
def self.find_by_slug_or_id(slug_or_id)
find_by_slug(slug_or_id) || find_by_id(slug_or_id)
end

def self.find_by_slug_or_id!(slug_or_id)
find_by_slug(slug_or_id) || find(slug_or_id)
end
end

def generate_slug
Expand Down