質問編集履歴

1

ソースの追加

2017/06/13 13:31

投稿

wk_rin
wk_rin

スコア27

test CHANGED
File without changes
test CHANGED
@@ -95,3 +95,239 @@
95
95
  知りたい情報がありましたら、質問をお願い致します。
96
96
 
97
97
  どうか助けてください。よろしくお願い致します。
98
+
99
+
100
+
101
+ 06/13 追記
102
+
103
+ conrollerとmodelの記述を追加します。
104
+
105
+ application_controllerとblogs_controllerの2箇所があります。
106
+
107
+
108
+
109
+ application_controller
110
+
111
+ ```ここに言語を入力
112
+
113
+ class ApplicationController < ActionController::Base
114
+
115
+ protect_from_forgery with: :exception
116
+
117
+
118
+
119
+ before_action :configure_permitted_parameters, if: :devise_controller?
120
+
121
+
122
+
123
+ protected
124
+
125
+ def configure_permitted_parameters
126
+
127
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:image])
128
+
129
+ devise_parameter_sanitizer.permit(:account_update, keys: [:image])
130
+
131
+ end
132
+
133
+ end
134
+
135
+ ```
136
+
137
+
138
+
139
+ blogs_controller
140
+
141
+ ```ここに言語を入力
142
+
143
+ class BlogsController < ApplicationController
144
+
145
+ before_action :set_blog, only: [:show, :edit, :update, :destroy]
146
+
147
+
148
+
149
+ # GET /blogs
150
+
151
+ # GET /blogs.json
152
+
153
+ def index
154
+
155
+ @blogs = Blog.all
156
+
157
+ end
158
+
159
+
160
+
161
+ # GET /blogs/1
162
+
163
+ # GET /blogs/1.json
164
+
165
+ def show
166
+
167
+ end
168
+
169
+
170
+
171
+ # GET /blogs/new
172
+
173
+ def new
174
+
175
+ @blog = Blog.new
176
+
177
+ end
178
+
179
+
180
+
181
+ # GET /blogs/1/edit
182
+
183
+ def edit
184
+
185
+ end
186
+
187
+
188
+
189
+ # POST /blogs
190
+
191
+ # POST /blogs.json
192
+
193
+ def create
194
+
195
+ @blog = Blog.new(blog_params)
196
+
197
+
198
+
199
+ respond_to do |format|
200
+
201
+ if @blog.save
202
+
203
+ format.html { redirect_to @blog, notice: 'Blog was successfully created.' }
204
+
205
+ format.json { render :show, status: :created, location: @blog }
206
+
207
+ else
208
+
209
+ format.html { render :new }
210
+
211
+ format.json { render json: @blog.errors, status: :unprocessable_entity }
212
+
213
+ end
214
+
215
+ end
216
+
217
+ end
218
+
219
+
220
+
221
+ # PATCH/PUT /blogs/1
222
+
223
+ # PATCH/PUT /blogs/1.json
224
+
225
+ def update
226
+
227
+ respond_to do |format|
228
+
229
+ if @blog.update(blog_params)
230
+
231
+ format.html { redirect_to @blog, notice: 'Blog was successfully updated.' }
232
+
233
+ format.json { render :show, status: :ok, location: @blog }
234
+
235
+ else
236
+
237
+ format.html { render :edit }
238
+
239
+ format.json { render json: @blog.errors, status: :unprocessable_entity }
240
+
241
+ end
242
+
243
+ end
244
+
245
+ end
246
+
247
+
248
+
249
+ # DELETE /blogs/1
250
+
251
+ # DELETE /blogs/1.json
252
+
253
+ def destroy
254
+
255
+ @blog.destroy
256
+
257
+ respond_to do |format|
258
+
259
+ format.html { redirect_to blogs_url, notice: 'Blog was successfully destroyed.' }
260
+
261
+ format.json { head :no_content }
262
+
263
+ end
264
+
265
+ end
266
+
267
+
268
+
269
+ private
270
+
271
+ # Use callbacks to share common setup or constraints between actions.
272
+
273
+ def set_blog
274
+
275
+ @blog = Blog.find(params[:id])
276
+
277
+ end
278
+
279
+
280
+
281
+ # Never trust parameters from the scary internet, only allow the white list through.
282
+
283
+ def blog_params
284
+
285
+ params.require(:blog).permit(:title, :content)
286
+
287
+ end
288
+
289
+ end
290
+
291
+
292
+
293
+ ```
294
+
295
+
296
+
297
+ model
298
+
299
+
300
+
301
+ application_record.rb
302
+
303
+ ```ここに言語を入力
304
+
305
+ class ApplicationRecord < ActiveRecord::Base
306
+
307
+ self.abstract_class = true
308
+
309
+ end
310
+
311
+ ```
312
+
313
+
314
+
315
+ blog.rb
316
+
317
+ ```ここに言語を入力
318
+
319
+ class Blog < ApplicationRecord
320
+
321
+
322
+
323
+ mount_uploader :image, ImageUploader
324
+
325
+
326
+
327
+
328
+
329
+ end
330
+
331
+
332
+
333
+ ```