-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlunchboxes_controller.rb
More file actions
67 lines (54 loc) · 1.4 KB
/
lunchboxes_controller.rb
File metadata and controls
67 lines (54 loc) · 1.4 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
class Admin::LunchboxesController < ApplicationController
before_action :set_lunchbox, only: [:show, :edit, :update, :destroy]
# GET /lunchboxes
def index
@lunchboxes = Lunchbox.all
end
# GET /lunchboxes/1
def show
end
# GET /lunchboxes/new
def new
@lunchbox = Lunchbox.new
end
# GET /lunchboxes/1/edit
def edit
end
# POST /lunchboxes
def create
@lunchbox = Lunchbox.new(lunchbox_params)
if @lunchbox.save
redirect_to admin_lunchboxes_path, notice: 'Lunchbox was successfully created.'
else
render :new
end
end
# PATCH/PUT /lunchboxes/1
def update
if @lunchbox.update(lunchbox_params)
redirect_to admin_lunchboxes_path, notice: 'Lunchbox was successfully updated.'
else
puts("#########")
puts("#########")
puts("#########")
render :edit, notice: '更新できませんでした'
end
end
# DELETE /lunchboxes/1
def destroy
@lunchbox.destroy
redirect_to lunchboxes_url, notice: 'Lunchbox was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_lunchbox
@lunchbox = Lunchbox.find(params[:id])
end
# # Only allow a trusted parameter "white list" through.
# def lunchbox_params
# params.fetch(:lunchbox, {})
# end
def lunchbox_params
params.require(:lunchbox).permit(:name, :price)
end
end