質問編集履歴
3
gemfileを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -104,6 +104,75 @@
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
```
|
107
|
+
```gemfile
|
108
|
+
source 'https://rubygems.org'
|
109
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
110
|
+
|
111
|
+
ruby '2.6.5'
|
112
|
+
|
113
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
114
|
+
gem 'rails', '~> 5.2.2'
|
115
|
+
# Use mysql as the database for Active Record
|
116
|
+
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
|
117
|
+
# Use Puma as the app server
|
118
|
+
gem 'puma', '~> 3.11'
|
119
|
+
# Use SCSS for stylesheets
|
120
|
+
gem 'sass-rails', '~> 5.0'
|
121
|
+
# Use Uglifier as compressor for JavaScript assets
|
122
|
+
gem 'uglifier', '>= 1.3.0'
|
123
|
+
# See https://github.com/rails/execjs#readme for more supported runtimes
|
124
|
+
# gem 'mini_racer', platforms: :ruby
|
125
|
+
gem 'jquery-rails'
|
126
|
+
|
127
|
+
# Use CoffeeScript for .coffee assets and views
|
128
|
+
gem 'coffee-rails', '~> 4.2'
|
129
|
+
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
|
130
|
+
gem 'turbolinks', '~> 5'
|
131
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
132
|
+
gem 'jbuilder', '~> 2.5'
|
133
|
+
# Use Redis adapter to run Action Cable in production
|
134
|
+
# gem 'redis', '~> 4.0'
|
135
|
+
# Use ActiveModel has_secure_password
|
136
|
+
# gem 'bcrypt', '~> 3.1.7'
|
137
|
+
|
138
|
+
# Use ActiveStorage variant
|
139
|
+
gem 'mini_magick', '~> 4.8'
|
140
|
+
gem 'image_processing'
|
141
|
+
# Use Capistrano for deployment
|
142
|
+
# gem 'capistrano-rails', group: :development
|
143
|
+
|
144
|
+
# Reduces boot times through caching; required in config/boot.rb
|
145
|
+
gem 'bootsnap', '>= 1.1.0', require: false
|
146
|
+
|
147
|
+
group :development, :test do
|
148
|
+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
149
|
+
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
150
|
+
gem 'devise'
|
151
|
+
gem 'carrierwave'
|
152
|
+
gem 'rmagick'
|
153
|
+
end
|
154
|
+
|
155
|
+
group :development do
|
156
|
+
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
|
157
|
+
gem 'web-console', '>= 3.3.0'
|
158
|
+
gem 'listen', '>= 3.0.5', '< 3.2'
|
159
|
+
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
160
|
+
gem 'spring'
|
161
|
+
gem 'spring-watcher-listen', '~> 2.0.0'
|
162
|
+
end
|
163
|
+
|
164
|
+
group :test do
|
165
|
+
# Adds support for Capybara system testing and selenium driver
|
166
|
+
gem 'capybara', '>= 2.15'
|
167
|
+
gem 'selenium-webdriver'
|
168
|
+
# Easy installation and use of chromedriver to run system tests with Chrome
|
169
|
+
gem 'chromedriver-helper'
|
170
|
+
end
|
171
|
+
|
172
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
173
|
+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
174
|
+
|
175
|
+
```
|
107
176
|
進展がありました`<td><%= post.image %></td>`にかえたところ、
|
108
177
|
以下の画像のようになりました
|
109
178
|

|
2
どこまでやれたのかを詳しく書きました
title
CHANGED
File without changes
|
body
CHANGED
@@ -104,6 +104,10 @@
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
```
|
107
|
+
進展がありました`<td><%= post.image %></td>`にかえたところ、
|
108
|
+
以下の画像のようになりました
|
109
|
+

|
110
|
+
|
107
111
|
##参考にした記事
|
108
112
|
[【Rails 5.2】 Active Storageの使い方
|
109
113
|
](https://qiita.com/hmmrjn/items/7cc5e5348755c517458a)
|
1
コードを書いていなかったので追加しました(comments_controller.rbとposts_controller.rb)。追加で質問した後手直ししたのでそちらのコードに書き直しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
<tr>
|
26
26
|
<td><%= post.title %></td>
|
27
27
|
<td><%= post.body %></td>
|
28
|
-
<td><%=
|
28
|
+
<td><%= post.image %></td>
|
29
29
|
</tr>
|
30
30
|
<% end %>
|
31
31
|
</table>
|
@@ -53,7 +53,57 @@
|
|
53
53
|
|
54
54
|
<% end %>
|
55
55
|
```
|
56
|
+
以下、posts_controller.rb
|
57
|
+
```
|
58
|
+
class PostsController < ApplicationController
|
59
|
+
def index
|
60
|
+
@posts = Post.all
|
61
|
+
end
|
56
62
|
|
63
|
+
def new
|
64
|
+
@post = Post.new
|
65
|
+
end
|
66
|
+
|
67
|
+
def create
|
68
|
+
@post = Post.new(post_params)
|
69
|
+
@post.save
|
70
|
+
redirect_to action: 'index'
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def post_params
|
75
|
+
params.require(:post).permit(:title, :body)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
いか、comment_controller.rb
|
80
|
+
```
|
81
|
+
class CommentsController < ApplicationController
|
82
|
+
def new
|
83
|
+
@comment = Comment.new
|
84
|
+
end
|
85
|
+
|
86
|
+
def create
|
87
|
+
@comment = Comment.create params.require(:comment).permit(:content, :image) # POINT
|
88
|
+
redirect_to @comment
|
89
|
+
end
|
90
|
+
|
91
|
+
def show
|
92
|
+
@comment = Comment.find(params[:id])
|
93
|
+
end
|
94
|
+
|
95
|
+
def edit
|
96
|
+
@comment = Comment.find(params[:id])
|
97
|
+
end
|
98
|
+
|
99
|
+
def update
|
100
|
+
@comment = Comment.find(params[:id])
|
101
|
+
@comment.update params.require(:comment).permit(:content, :image) # POINT
|
102
|
+
@Comment.avatar.attach(params[:avatar])
|
103
|
+
redirect_to @commtnt
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
57
107
|
##参考にした記事
|
58
108
|
[【Rails 5.2】 Active Storageの使い方
|
59
109
|
](https://qiita.com/hmmrjn/items/7cc5e5348755c517458a)
|