質問編集履歴

3

gemfileを追加しました

2021/01/26 05:55

投稿

kawasaki4563
kawasaki4563

スコア32

test CHANGED
File without changes
test CHANGED
@@ -210,6 +210,144 @@
210
210
 
211
211
  ```
212
212
 
213
+ ```gemfile
214
+
215
+ source 'https://rubygems.org'
216
+
217
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
218
+
219
+
220
+
221
+ ruby '2.6.5'
222
+
223
+
224
+
225
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
226
+
227
+ gem 'rails', '~> 5.2.2'
228
+
229
+ # Use mysql as the database for Active Record
230
+
231
+ gem 'mysql2', '>= 0.4.4', '< 0.6.0'
232
+
233
+ # Use Puma as the app server
234
+
235
+ gem 'puma', '~> 3.11'
236
+
237
+ # Use SCSS for stylesheets
238
+
239
+ gem 'sass-rails', '~> 5.0'
240
+
241
+ # Use Uglifier as compressor for JavaScript assets
242
+
243
+ gem 'uglifier', '>= 1.3.0'
244
+
245
+ # See https://github.com/rails/execjs#readme for more supported runtimes
246
+
247
+ # gem 'mini_racer', platforms: :ruby
248
+
249
+ gem 'jquery-rails'
250
+
251
+
252
+
253
+ # Use CoffeeScript for .coffee assets and views
254
+
255
+ gem 'coffee-rails', '~> 4.2'
256
+
257
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
258
+
259
+ gem 'turbolinks', '~> 5'
260
+
261
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
262
+
263
+ gem 'jbuilder', '~> 2.5'
264
+
265
+ # Use Redis adapter to run Action Cable in production
266
+
267
+ # gem 'redis', '~> 4.0'
268
+
269
+ # Use ActiveModel has_secure_password
270
+
271
+ # gem 'bcrypt', '~> 3.1.7'
272
+
273
+
274
+
275
+ # Use ActiveStorage variant
276
+
277
+ gem 'mini_magick', '~> 4.8'
278
+
279
+ gem 'image_processing'
280
+
281
+ # Use Capistrano for deployment
282
+
283
+ # gem 'capistrano-rails', group: :development
284
+
285
+
286
+
287
+ # Reduces boot times through caching; required in config/boot.rb
288
+
289
+ gem 'bootsnap', '>= 1.1.0', require: false
290
+
291
+
292
+
293
+ group :development, :test do
294
+
295
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
296
+
297
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
298
+
299
+ gem 'devise'
300
+
301
+ gem 'carrierwave'
302
+
303
+ gem 'rmagick'
304
+
305
+ end
306
+
307
+
308
+
309
+ group :development do
310
+
311
+ # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
312
+
313
+ gem 'web-console', '>= 3.3.0'
314
+
315
+ gem 'listen', '>= 3.0.5', '< 3.2'
316
+
317
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
318
+
319
+ gem 'spring'
320
+
321
+ gem 'spring-watcher-listen', '~> 2.0.0'
322
+
323
+ end
324
+
325
+
326
+
327
+ group :test do
328
+
329
+ # Adds support for Capybara system testing and selenium driver
330
+
331
+ gem 'capybara', '>= 2.15'
332
+
333
+ gem 'selenium-webdriver'
334
+
335
+ # Easy installation and use of chromedriver to run system tests with Chrome
336
+
337
+ gem 'chromedriver-helper'
338
+
339
+ end
340
+
341
+
342
+
343
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
344
+
345
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
346
+
347
+
348
+
349
+ ```
350
+
213
351
  進展がありました`<td><%= post.image %></td>`にかえたところ、
214
352
 
215
353
  以下の画像のようになりました

2

どこまでやれたのかを詳しく書きました

2021/01/26 05:55

投稿

kawasaki4563
kawasaki4563

スコア32

test CHANGED
File without changes
test CHANGED
@@ -210,6 +210,14 @@
210
210
 
211
211
  ```
212
212
 
213
+ 進展がありました`<td><%= post.image %></td>`にかえたところ、
214
+
215
+ 以下の画像のようになりました
216
+
217
+ ![イメージ説明](b92dcd6e48e547ba52d63eaa8fdbe666.png)
218
+
219
+
220
+
213
221
  ##参考にした記事
214
222
 
215
223
  [【Rails 5.2】 Active Storageの使い方

1

コードを書いていなかったので追加しました(comments_controller.rbとposts_controller.rb)。追加で質問した後手直ししたのでそちらのコードに書き直しました

2021/01/26 01:02

投稿

kawasaki4563
kawasaki4563

スコア32

test CHANGED
File without changes
test CHANGED
@@ -52,7 +52,7 @@
52
52
 
53
53
  <td><%= post.body %></td>
54
54
 
55
- <td><%= image_tag user.image %></td>
55
+ <td><%= post.image %></td>
56
56
 
57
57
  </tr>
58
58
 
@@ -108,7 +108,107 @@
108
108
 
109
109
  ```
110
110
 
111
-
111
+ 以下、posts_controller.rb
112
+
113
+ ```
114
+
115
+ class PostsController < ApplicationController
116
+
117
+ def index
118
+
119
+ @posts = Post.all
120
+
121
+ end
122
+
123
+
124
+
125
+ def new
126
+
127
+ @post = Post.new
128
+
129
+ end
130
+
131
+
132
+
133
+ def create
134
+
135
+ @post = Post.new(post_params)
136
+
137
+ @post.save
138
+
139
+ redirect_to action: 'index'
140
+
141
+ end
142
+
143
+
144
+
145
+ private
146
+
147
+ def post_params
148
+
149
+ params.require(:post).permit(:title, :body)
150
+
151
+ end
152
+
153
+ end
154
+
155
+ ```
156
+
157
+ いか、comment_controller.rb
158
+
159
+ ```
160
+
161
+ class CommentsController < ApplicationController
162
+
163
+ def new
164
+
165
+ @comment = Comment.new
166
+
167
+ end
168
+
169
+
170
+
171
+ def create
172
+
173
+ @comment = Comment.create params.require(:comment).permit(:content, :image) # POINT
174
+
175
+ redirect_to @comment
176
+
177
+ end
178
+
179
+
180
+
181
+ def show
182
+
183
+ @comment = Comment.find(params[:id])
184
+
185
+ end
186
+
187
+
188
+
189
+ def edit
190
+
191
+ @comment = Comment.find(params[:id])
192
+
193
+ end
194
+
195
+
196
+
197
+ def update
198
+
199
+ @comment = Comment.find(params[:id])
200
+
201
+ @comment.update params.require(:comment).permit(:content, :image) # POINT
202
+
203
+ @Comment.avatar.attach(params[:avatar])
204
+
205
+ redirect_to @commtnt
206
+
207
+ end
208
+
209
+ end
210
+
211
+ ```
112
212
 
113
213
  ##参考にした記事
114
214