Module: ModelExt::Restaurants::PrimaryTags
- Included in:
- Restaurant
- Defined in:
- lib/model_ext/restaurants/primary_tags.rb
Overview
instance methods regarding primary tags relation for restaurant
Instance Method Summary collapse
-
#primary_tag_by_category(category) ⇒ PrimaryTag?
Finds the primary tag for a given category.
Instance Method Details
#primary_tag_by_category(category) ⇒ PrimaryTag?
Finds the primary tag for a given category.
If the category is a location category, it tries to find a matching tag. If not found, it falls back to the popular zone category. For other categories, it finds the first matching tag.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/model_ext/restaurants/primary_tags.rb', line 13 def primary_tag_by_category(category) return nil if category.blank? || .blank? if RestaurantTag::LOCATION_CATEGORIES.include?(category) primary_tag_location = .joins(:restaurant_tag). where('restaurant_tags.title_en LIKE ?', "#{category}%")&.first # if primary_tag_location is nil, try to find popularzone by default primary_tag_location.presence || .joins(:restaurant_tag). where('restaurant_tags.title_en LIKE ?', "#{RestaurantTag::POPULAR_ZONE}%")&.first else .joins(:restaurant_tag). where('restaurant_tags.title_en LIKE ?', "#{category}%")&.first end end |