-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path'
44 lines (35 loc) · 893 Bytes
/
'
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
class RestaurantsController < ApplicationController
def index
@restaurants = Restaurant.all
end
# GET /restaurants/:id
def show
@restaurant = Restaurant.find(params[:id])
end
# GET /restaurants/new
def new
@restaurant = Restaurant.new
end
# POST /restaurants
# params[:restaurnt] = { name:..., rating:..., address:...}
def create
@restaurant = Restaurant.new(restaurant_params)
@restaurant.save
redirect_to restaurant_path(@restaurant)
end
# GET /restaurants/:id
def edit
@restaurant = Restaurant.find(params[:id])
end
# PATCH /restaurants/:id
def update
@restaurant = Restaurant.find(params[:id])
@restaurant.update(restaurant_params)
redirect_to restaurant_path(@restaurant)
end
private
# strong params
def restaurant_params
params.require(:restaurant).permit(:name, :address, :rating)
end
end