Class: RoomTypeSlugConstraint
- Inherits:
-
Object
- Object
- RoomTypeSlugConstraint
- Defined in:
- lib/room_type_slug_constraint.rb
Overview
Routing constraint that only matches when params[:room_type] is
the slug of a real RoomType. Lets the public site keep nice
/floor-heating/bathroom-style URLs without 404'ing on arbitrary
garbage path segments.
Instance Method Summary collapse
-
#matches?(request) ⇒ Boolean
Matches only when the provided slug corresponds to an existing RoomType.
Instance Method Details
#matches?(request) ⇒ Boolean
Matches only when the provided slug corresponds to an existing RoomType
8 9 10 11 12 13 14 15 16 |
# File 'lib/room_type_slug_constraint.rb', line 8 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 |