Class: Deals::DealsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/deals_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/deals_controller.rb', line 4

def index
  place = params[:place]
  category = params[:category]

  if place.present?
    places = Place.where(:slug => place)
    place_id = places.first.id if places.any?
  end

  if category.present?
    categories = Category.where(:slug => category)
    category_id = categories.first.id if categories.any?
  end

  if place_id.present? && category_id.present? 
    @deals = Deal.where(:place_id => place_id, :category_id => category_id)
  elsif place_id.present?
    @deals = Deal.where(:place_id => place_id)
  elsif category_id.present?
    @deals = Deal.where(:category_id => category_id)
  else
    @deals = Deal.all
  end

  respond_with(@deals)
end