File size: 1,228 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

class Api::SpotsController < ApplicationController
  def index
    @spots = bounds ? Spot.in_bounds(bounds).with_attached_photos : Spot.all.with_attached_photos
    
    if @spots
      render :index  
    else
      render json: ["No Spots"], status: 422
    end
  end

  def show
    @spot = Spot.with_attached_photos.find(params[:id])

    if @spot
      render :show
    else
      render json: ["No Spot"], status: 422
    end
  end
  
  private

  def spot_params
    params.require(:listing).permit(:title, :description, :num_guests, :listing_type, :num_beds, :num_baths, :price,:location, :loc_detail, :lat, :lng, :host_id, photos: [])
  end

  def bounds
    params[:bounds]
  end

end


# class Api::SpotsController < ApplicationController

#     def index
#         # @spots = Spot.in_bounds(params[:bounds])
#         @spots = Spot.all
#         render 'api/spots/index'
#     end

#     def show
#         @spot = Spot.find(params[:id])
#         render 'api/spots/show'
#     end

#     private
#     def spot_params
#         params.require(:listing).permit(:title, :description, :num_guests, :listing_type, :num_beds, :num_baths, :price,:location, :loc_detail, :lat, :lng, :host_id, photos: [])
#     end

# end