module Sluggable
  extend ActiveSupport::Concern

  included do
    before_validation :generate_slug, if: :generate_slug?
  end

  def generate_slug
    self.slug = name.to_s.parameterize
  end
end

module Sluggable
  extend ActiveSupport::Concern

  included do
    before_validation :generate_slug, if: :generate_slug?

    def self.find_by_slug_or_id(slug_or_id)
      find_by_slug(slug_or_id) || find_by_id(slug_or_id)
    end
  end

  def generate_slug
    self.slug = name.to_s.parameterize
  end
end

Add method find_by_slug_or_id to Sluggable module
Add method find_by_slug_or_id to Sluggable module

Make it easier to find by slug or id for sluggable models. Will return
nil if resource is not found.
