質問編集履歴
1
controllerクラスの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,4 +62,100 @@
|
|
62
62
|
|
63
63
|
|
64
64
|
|
65
|
+
|
66
|
+
|
67
|
+
posts_controller.rb
|
68
|
+
|
69
|
+
```ここに言語を入力
|
70
|
+
|
71
|
+
class PostsController < ApplicationController
|
72
|
+
|
73
|
+
def index
|
74
|
+
|
75
|
+
@posts = Post.all.order(created_at: :desc)
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
def show
|
82
|
+
|
83
|
+
@post = Post.find_by(id: params[:id])
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def new
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
def create
|
96
|
+
|
97
|
+
@post = Post.new(content: params[:content])
|
98
|
+
|
99
|
+
@post.save
|
100
|
+
|
101
|
+
redirect_to("/posts/index")
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
def edit
|
108
|
+
|
109
|
+
@post = Post.find_by(id: params[:id])
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
def update
|
116
|
+
|
117
|
+
@post = Post.find_by(id: params[:id])
|
118
|
+
|
119
|
+
@post.content = params[:content]
|
120
|
+
|
121
|
+
if @post.save
|
122
|
+
|
123
|
+
redirect_to("/posts/index")
|
124
|
+
|
125
|
+
else
|
126
|
+
|
127
|
+
render("posts/edit")
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
def destroy
|
136
|
+
|
137
|
+
@post = Post.find_by(id: params[:id])
|
138
|
+
|
139
|
+
@post.destroy
|
140
|
+
|
141
|
+
redirect_to("/posts/index")
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
65
161
|
よろしくお願いいたします。
|