質問編集履歴

1

branches_controller\.rb の追加

2017/06/22 08:14

投稿

ak_suzuki
ak_suzuki

スコア194

test CHANGED
File without changes
test CHANGED
@@ -80,4 +80,142 @@
80
80
 
81
81
 
82
82
 
83
+ なお、コントローラーは下記のようにscaffoldのほぼデフォルトです。
84
+
85
+
86
+
87
+ branches_controller.rb
88
+
89
+
90
+
91
+ ```class BranchesController < ApplicationController
92
+
93
+ before_action :set_branch, only: [:show, :edit, :update, :destroy]
94
+
95
+
96
+
97
+ def index
98
+
99
+ @branches = Branch.all
100
+
101
+ end
102
+
103
+
104
+
105
+ def show
106
+
107
+ end
108
+
109
+
110
+
111
+ def new
112
+
113
+ @branch = Branch.new
114
+
115
+ end
116
+
117
+
118
+
119
+ def edit
120
+
121
+ end
122
+
123
+
124
+
125
+ def create
126
+
127
+ @branch = Branch.new(branch_params)
128
+
129
+
130
+
131
+ respond_to do |format|
132
+
133
+ if @branch.save
134
+
135
+ format.html { redirect_to @branch, notice: 'Branch was successfully created.' }
136
+
137
+ format.json { render :show, status: :created, location: @branch }
138
+
139
+ else
140
+
141
+ format.html { render :new }
142
+
143
+ format.json { render json: @branch.errors, status: :unprocessable_entity }
144
+
145
+ end
146
+
147
+ end
148
+
149
+ end
150
+
151
+
152
+
153
+ def update
154
+
155
+ respond_to do |format|
156
+
157
+ if @branch.update(branch_params)
158
+
159
+ format.html { redirect_to @branch, notice: 'Branch was successfully updated.' }
160
+
161
+ format.json { render :show, status: :ok, location: @branch }
162
+
163
+ else
164
+
165
+ format.html { render :edit }
166
+
167
+ format.json { render json: @branch.errors, status: :unprocessable_entity }
168
+
169
+ end
170
+
171
+ end
172
+
173
+ end
174
+
175
+
176
+
177
+ def destroy
178
+
179
+ @branch.destroy
180
+
181
+ respond_to do |format|
182
+
183
+ format.html { redirect_to branches_url, notice: 'Branch was successfully destroyed.' }
184
+
185
+ format.json { head :no_content }
186
+
187
+ end
188
+
189
+ end
190
+
191
+
192
+
193
+ private
194
+
195
+ def set_branch
196
+
197
+ @branch = Branch.find(params[:id])
198
+
199
+ end
200
+
201
+
202
+
203
+ def branch_params
204
+
205
+ params.require(:branch).permit(:bank_cd, :branch_cd, :branch_name)
206
+
207
+ end
208
+
209
+ end
210
+
211
+
212
+
213
+ ```
214
+
215
+
216
+
217
+
218
+
219
+
220
+
83
221
  どなたか、お力添え願えますでしょうか。