質問編集履歴
6
みやすくするため
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -194,61 +194,4 @@
|
|
|
194
194
|
if @post.user_id == current_user.id
|
|
195
195
|
post.update(post_params) 赤のライン
|
|
196
196
|
end
|
|
197
|
-
end
|
|
197
|
+
end
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
解決方法
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
class PostsController < ApplicationController
|
|
211
|
-
def index
|
|
212
|
-
|
|
213
|
-
@posts = Post.all
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def new
|
|
217
|
-
@post = Post.new
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def create
|
|
221
|
-
Post.create(post_params)
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
def edit
|
|
226
|
-
@post = Post.find(params[:id])
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
def show
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def update
|
|
235
|
-
@post = Post.find(params[:id])
|
|
236
|
-
if post.user_id == current_user.id
|
|
237
|
-
post.update(post_params)
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def destroy
|
|
243
|
-
post = Post.find(params[:id])
|
|
244
|
-
if post.user_id == current_user.id
|
|
245
|
-
post.destroy
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
private
|
|
251
|
-
def post_params
|
|
252
|
-
params.require(:post).permit(:text).merge(user_id: current_user.id)
|
|
253
|
-
end
|
|
254
|
-
end
|
5
みやすくするため
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -197,4 +197,58 @@
|
|
|
197
197
|
end
|
|
198
198
|
|
|
199
199
|
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
解決方法
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
class PostsController < ApplicationController
|
|
211
|
+
def index
|
|
212
|
+
|
|
213
|
+
@posts = Post.all
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def new
|
|
217
|
+
@post = Post.new
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def create
|
|
221
|
+
Post.create(post_params)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def edit
|
|
226
|
+
@post = Post.find(params[:id])
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def show
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def update
|
|
235
|
+
@post = Post.find(params[:id])
|
|
236
|
+
if post.user_id == current_user.id
|
|
237
|
+
post.update(post_params)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def destroy
|
|
243
|
+
post = Post.find(params[:id])
|
|
244
|
+
if post.user_id == current_user.id
|
|
245
|
+
post.destroy
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
private
|
|
251
|
+
def post_params
|
|
200
|
-
|
|
252
|
+
params.require(:post).permit(:text).merge(user_id: current_user.id)
|
|
253
|
+
end
|
|
254
|
+
end
|
4
みやすくするため
title
CHANGED
|
@@ -1,1 +1,1 @@
|
|
|
1
|
-
railsにおいて編集が反映されない件について
|
|
1
|
+
srailsにおいて編集が反映されない件について
|
body
CHANGED
|
@@ -104,9 +104,6 @@
|
|
|
104
104
|
def show
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
def update
|
|
108
|
-
end
|
|
109
|
-
|
|
110
107
|
def destroy
|
|
111
108
|
post = Post.find(params[:id])
|
|
112
109
|
if post.user_id == current_user.id
|
|
@@ -172,4 +169,32 @@
|
|
|
172
169
|
|
|
173
170
|
|
|
174
171
|
|
|
175
|
-
どうかお力を貸していただけると助かります。よろしくお願いします。
|
|
172
|
+
どうかお力を貸していただけると助かります。よろしくお願いします。
|
|
173
|
+
|
|
174
|
+
postcontroller
|
|
175
|
+
|
|
176
|
+
def update
|
|
177
|
+
@post = Post.find(params[:id])
|
|
178
|
+
if @post.user_id == current_user.id
|
|
179
|
+
post.update(post_params)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
postから@postに変更させていただきました。
|
|
185
|
+
|
|
186
|
+
結果このようにエラーが出ました。
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
NameError in PostsController#update
|
|
191
|
+
undefined local variable or method `post' for #<> Did you mean? @post
|
|
192
|
+
|
|
193
|
+
@post = Post.find(params[:id])
|
|
194
|
+
if @post.user_id == current_user.id
|
|
195
|
+
post.update(post_params) 赤のライン
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
Parameters: {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"", "post"=>{"text"=>"s"}, "commit"=>"投稿", "id"=>"5"}
|
3
みやすくするため
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
dddddd 投稿
|
|
26
26
|
|
|
27
27
|
---
|
|
28
|
-
このようになるのでddddddの部分をupdatedに変えて
|
|
28
|
+
このようになるのでddddddの部分をupdatedに変えて
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
ログインアプリ
|
|
@@ -35,7 +35,17 @@
|
|
|
35
35
|
updated 投稿
|
|
36
36
|
|
|
37
37
|
---
|
|
38
|
+
投稿ボタンを押して
|
|
39
|
+
http://localhost:3000/posts/5
|
|
40
|
+
---
|
|
41
|
+
ログインアプリ
|
|
42
|
+
ログアウト
|
|
43
|
+
マイページ
|
|
44
|
+
投稿する
|
|
45
|
+
you posted
|
|
46
|
+
go to home
|
|
47
|
+
---
|
|
38
|
-
|
|
48
|
+
go to homeを押してホームに戻っても
|
|
39
49
|
|
|
40
50
|
http://localhost:3000/posts
|
|
41
51
|
|
2
みやすくするため
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
```routes
|
|
57
57
|
Rails.application.routes.draw do
|
|
58
58
|
devise_for :users
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
root to: 'posts#index'
|
|
61
61
|
resources :posts
|
|
62
62
|
resources :users
|
1
みやすくするため
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
ログインアプリ
|
|
32
|
-
メールアドレス: 1@1
|
|
33
32
|
ログアウト
|
|
34
33
|
マイページ
|
|
35
34
|
投稿する
|