Class: RoomTypeSlugConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/room_type_slug_constraint.rb

Instance Method Summary collapse

Instance Method Details

#matches?(request) ⇒ Boolean

Matches only when the provided slug corresponds to an existing RoomType

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
# File 'lib/room_type_slug_constraint.rb', line 3

def matches?(request)
  slug = request.params[:room_type].to_s
  return false if slug.blank?

  RoomType.exists?([
    "seo_key = :slug OR LOWER(friendly_name) = :slug OR LOWER(REPLACE(name, ' ', '-')) = :slug",
    { slug: slug.downcase }
  ])
end