質問編集履歴

5

index.htmlの修正後を追記

2019/11/24 05:27

投稿

Yuki.C
Yuki.C

スコア5

test CHANGED
File without changes
test CHANGED
@@ -213,3 +213,37 @@
213
213
  (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
214
214
 
215
215
  ↳ /home/ec2-user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
216
+
217
+
218
+
219
+ ### index.html.erbの修正後
220
+
221
+ <% @blogs.each do |blog| %>
222
+
223
+ <div class="kakomi-box1">
224
+
225
+ <p class="title"><%= blog.title %></p>
226
+
227
+ <p class="text"><%= blog.text %></p>
228
+
229
+ <p class="date"><%= blog.created_at.try(:strftime,"%Y年%m月%d日") %></p>
230
+
231
+ <p class="id"><%= blog.user_id %>の投稿です。</p>
232
+
233
+ <% if user_signed_in? && current_user.id == blog.user_id %>
234
+
235
+ <%= link_to '削除', blog_path(blog),class:'cp_btn2', method: :delete %>
236
+
237
+ <a href="#" class="cp_btn1">編集</a>
238
+
239
+ <a href="#" class="cp_btn2">詳細</a>
240
+
241
+ <% else %>
242
+
243
+ <a href="#" class="cp_btn2">コメント</a>
244
+
245
+ <% end %>
246
+
247
+ </div>
248
+
249
+ <% end %>

4

処理したあとの結果内容について追記

2019/11/24 05:27

投稿

Yuki.C
Yuki.C

スコア5

test CHANGED
File without changes
test CHANGED
@@ -197,3 +197,19 @@
197
197
  end
198
198
 
199
199
  '''
200
+
201
+
202
+
203
+ ### <%= link_to '削除', blog_path(blog),class:'cp_btn2', method: :delete %>の結果の処理
204
+
205
+ Started DELETE "/blogs.30" for 126.165.251.179 at 2019-11-19 15:38:13 +0000
206
+
207
+ Cannot render console from 126.165.251.179! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
208
+
209
+ (0.3ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
210
+
211
+ ↳ /home/ec2-user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
212
+
213
+ (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
214
+
215
+ ↳ /home/ec2-user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98

3

routes.rbを追記

2019/11/19 15:40

投稿

Yuki.C
Yuki.C

スコア5

test CHANGED
File without changes
test CHANGED
@@ -174,8 +174,26 @@
174
174
 
175
175
  <% end %>
176
176
 
177
- ### 補足情報(FW/ツールのバージョンなど)
177
+ ### routes.rbを追記
178
178
 
179
+ '''
179
180
 
181
+ Rails.application.routes.draw do
180
182
 
183
+ devise_for :users
184
+
185
+ root 'blogs#index'
186
+
187
+ get 'blogs' => 'blogs#index'
188
+
189
+ get 'blogs/new' => 'blogs#new'
190
+
191
+ post 'blogs' => 'blogs#create'
192
+
193
+ delete '/blogs/:id' => 'blogs#destroy'
194
+
195
+ get 'blogs/:id/edit' => 'blogs#edit'
196
+
197
+ end
198
+
181
- ここにより詳細な情報を記載してください。
199
+ '''

2

index.htmlを追加

2019/11/19 15:35

投稿

Yuki.C
Yuki.C

スコア5

test CHANGED
File without changes
test CHANGED
@@ -142,13 +142,37 @@
142
142
 
143
143
 
144
144
 
145
- ### 試したこと
145
+ ### index.html
146
146
 
147
147
 
148
148
 
149
- idの引き渡しをしましたが、うまくできませんでした。
149
+ <% @blogs.each do |blog| %>
150
150
 
151
+ <div class="kakomi-box1">
151
152
 
153
+ <p class="title"><%= blog.title %></p>
154
+
155
+ <p class="text"><%= blog.text %></p>
156
+
157
+ <p class="date"><%= blog.created_at.try(:strftime,"%Y年%m月%d日") %></p>
158
+
159
+ <p class="id"><%= blog.user_id %>の投稿です。</p>
160
+
161
+ <% if user_signed_in? %>
162
+
163
+ <%= link_to '削除', "/blogs/:id/destroy",class:'cp_btn2', method: :delete %>
164
+
165
+ <a href="#" class="cp_btn1">編集</a>
166
+
167
+ <% else %>
168
+
169
+ <a href="#" class="cp_btn2">詳細</a>
170
+
171
+ <% end %>
172
+
173
+ </div>
174
+
175
+ <% end %>
152
176
 
153
177
  ### 補足情報(FW/ツールのバージョンなど)
154
178
 

1

destroyのhtml、処理をした際のlogを追加しました。

2019/11/19 12:26

投稿

Yuki.C
Yuki.C

スコア5

test CHANGED
File without changes
test CHANGED
@@ -88,6 +88,60 @@
88
88
 
89
89
 
90
90
 
91
+ ### destroy のHTML
92
+
93
+ <div class="contents row">
94
+
95
+ <div class="success">
96
+
97
+ <h3>
98
+
99
+ 削除が完了しました。
100
+
101
+ </h3>
102
+
103
+ <a class="btn" href="/">投稿一覧へ戻る</a>
104
+
105
+ </div>
106
+
107
+ </div>
108
+
109
+
110
+
111
+ ### 処理をした際のlog
112
+
113
+ ↳ /home/ec2-user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
114
+
115
+ (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
116
+
117
+ ↳ /home/ec2-user/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
118
+
119
+ /home/ec2-user/environment/blog2/app/controllers/blogs_controller.rb:35: warning: else without rescue is useless
120
+
121
+ Processing by BlogsController#destroy as HTML
122
+
123
+ Parameters: {"authenticity_token"=>"o1HHz2cavK9DwfiGyHqJqTKeHuMIdUdx/ZF59McYM4QvMbtKwF/SSxoA4SWeIs5oXztcYlXtodV3Q1oWeu4ayA==", "id"=>":user_id"}
124
+
125
+ Blog Load (0.2ms) SELECT `blogs`.* FROM `blogs` WHERE `blogs`.`id` = 0 LIMIT 1
126
+
127
+ ↳ app/controllers/blogs_controller.rb:30
128
+
129
+ Completed 500 Internal Server Error in 13ms (ActiveRecord: 0.7ms)
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+ NoMethodError (undefined method `destroy' for nil:NilClass):
138
+
139
+
140
+
141
+ app/controllers/blogs_controller.rb:31:in `destroy'
142
+
143
+
144
+
91
145
  ### 試したこと
92
146
 
93
147