質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,3 +11,105 @@
|
|
11
11
|
このエラー(`[]=' )は何を示しているのですか?
|
12
12
|
|
13
13
|
例えば'title'などであれば titleがnilなんだなとわかるのですが、今回のエラーは初めてで全くわかりません
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```ここに言語を入力
|
18
|
+
|
19
|
+
class PostsController < ApplicationController
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
before_action :authenticate_user
|
24
|
+
|
25
|
+
before_action :ensure_correct_user, {only: [:edit, :update, :destroy]}
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
def index
|
30
|
+
|
31
|
+
@posts = Post.all.order(created_at: :desc)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def show
|
38
|
+
|
39
|
+
@post = Post.find_by(id: params[:id])
|
40
|
+
|
41
|
+
@user = @post.user
|
42
|
+
|
43
|
+
@likes_count = Like.where(post_id: @post.id).count
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
def new
|
50
|
+
|
51
|
+
@post = Post.new
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
def create
|
58
|
+
|
59
|
+
post = Post.new(
|
60
|
+
|
61
|
+
post_params.merge(user_id: @current_user.id)
|
62
|
+
|
63
|
+
)
|
64
|
+
|
65
|
+
post.save
|
66
|
+
|
67
|
+
redirect_to("/")
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def destroy
|
74
|
+
|
75
|
+
@post = Post.find_by(id: params[:id])
|
76
|
+
|
77
|
+
@post.destroy
|
78
|
+
|
79
|
+
flash[:notice] = "削除"
|
80
|
+
|
81
|
+
redirect_to("/")
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def ensure_correct_user
|
88
|
+
|
89
|
+
@post = Post.find_by(id: params[:id])
|
90
|
+
|
91
|
+
if @post.user_id != @current_user.id
|
92
|
+
|
93
|
+
flash[:notice] = "権限がありません"
|
94
|
+
|
95
|
+
redirect_to("/posts/index")
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def post_params
|
106
|
+
|
107
|
+
params.require(:post).permit(:content, :image, :tag_list)
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
```
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,3 +9,5 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
このエラー(`[]=' )は何を示しているのですか?
|
12
|
+
|
13
|
+
例えば'title'などであれば titleがnilなんだなとわかるのですが、今回のエラーは初めてで全くわかりません
|