質問編集履歴
1
communities_controller.rbの記述を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,117 @@
|
|
123
123
|
```
|
124
124
|
|
125
125
|
なぜcommunity_participantのidが取得出来ないのでしょうか?
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
以下追記しました。
|
138
|
+
|
139
|
+
communities_controller.rb
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
|
143
|
+
before_action :set_community, only: [:show, :edit, :update, :destroy]
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
def index
|
148
|
+
|
149
|
+
@communities = Community.order(id: :desc).page(params[:page]).per(3)
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
def new
|
156
|
+
|
157
|
+
@community = current_user.communities.build
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
def create
|
164
|
+
|
165
|
+
@community = current_user.communities.build(community_params)
|
166
|
+
|
167
|
+
if @community.save
|
168
|
+
|
169
|
+
redirect_to communities_path
|
170
|
+
|
171
|
+
else
|
172
|
+
|
173
|
+
render :new
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
def show
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def edit
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
def update
|
194
|
+
|
195
|
+
if @community.update(community_params)
|
196
|
+
|
197
|
+
redirect_to @community
|
198
|
+
|
199
|
+
else
|
200
|
+
|
201
|
+
render :edit
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
def destroy
|
210
|
+
|
211
|
+
@community.destroy
|
212
|
+
|
213
|
+
redirect_to communities_path
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
private
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
def community_params
|
224
|
+
|
225
|
+
params.require(:community).permit(:name, :description)
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
def set_community
|
232
|
+
|
233
|
+
@community = Community.find(params[:id])
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
```
|