質問編集履歴
2
開発環境を追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
###前提・分からないこと
|
2
2
|
|
3
|
+
|
4
|
+
|
5
|
+
開発環境:Ruby on Rails 5.0.0.1
|
6
|
+
|
7
|
+
|
8
|
+
|
3
9
|
Ruby(RubyonRails)で食べログのようなレビューサイトを作成しています。
|
4
10
|
|
5
11
|
レストランの詳細ページ上で『レビュー登録ボタン』を設置し、モーダル登場でレビュー登録ができるようにしようと考えています。
|
1
コントローラー、ビューのコードを変更しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -187,3 +187,141 @@
|
|
187
187
|
end
|
188
188
|
|
189
189
|
```
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
###追記分
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
変更してやってみたのですが、なかなかうまくいきません(涙
|
198
|
+
|
199
|
+
ビューは表示されるのですが、f.submitを押しても一切動かないのです!(T_T)
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
・ビュー
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
```Ruby
|
208
|
+
|
209
|
+
・・・
|
210
|
+
|
211
|
+
<!-- Modal -->
|
212
|
+
|
213
|
+
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="z-index: 30000;">
|
214
|
+
|
215
|
+
<div class="modal-dialog" role="document">
|
216
|
+
|
217
|
+
<div class="modal-content">
|
218
|
+
|
219
|
+
<%= form_for(@review) do |f| %>
|
220
|
+
|
221
|
+
<%= render 'shared/error_messages', object: f.object %>
|
222
|
+
|
223
|
+
<div class="modal-body">
|
224
|
+
|
225
|
+
<div class="title page-form account-form">
|
226
|
+
|
227
|
+
<h2>口コミを登録する</h2>
|
228
|
+
|
229
|
+
<form>
|
230
|
+
|
231
|
+
<div class="form-group review-form-restaurant">
|
232
|
+
|
233
|
+
<h3><%= @restaurant.name %></h3>
|
234
|
+
|
235
|
+
<%= f.hidden_field :restaurant_id, :value => @restaurant.id %>
|
236
|
+
|
237
|
+
</div>
|
238
|
+
|
239
|
+
<div class="form-group">
|
240
|
+
|
241
|
+
<label for="exampleInputName">口コミを入力する</label><br />
|
242
|
+
|
243
|
+
<%= f.select :rate, {'1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5,}, class: "form-control" %>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<div class="form-group">
|
248
|
+
|
249
|
+
<%= f.text_field :title, class: "form-control", placeholder: "タイトル" %>
|
250
|
+
|
251
|
+
</div>
|
252
|
+
|
253
|
+
<div class="form-group">
|
254
|
+
|
255
|
+
<%= f.text_area :content, class: "form-control", placeholder: "口コミ内容", rows: "5" %>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
</form>
|
260
|
+
|
261
|
+
</div>
|
262
|
+
|
263
|
+
</div>
|
264
|
+
|
265
|
+
<div class="modal-footer">
|
266
|
+
|
267
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">閉じる</button>
|
268
|
+
|
269
|
+
<%= f.submit "投稿する", class: "btn btn-form btn-modal" %>
|
270
|
+
|
271
|
+
</div>
|
272
|
+
|
273
|
+
</div>
|
274
|
+
|
275
|
+
<% end %>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
</div>
|
280
|
+
|
281
|
+
・・・
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
・コントローラー(restaurant)
|
288
|
+
|
289
|
+
```Ruby
|
290
|
+
|
291
|
+
class RestaurantsController < ApplicationController
|
292
|
+
|
293
|
+
before_action :logged_in_user, only: :create
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
def show
|
298
|
+
|
299
|
+
@review = current_user.reviews.build if logged_in?
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
def create
|
306
|
+
|
307
|
+
@review = current_user.reviews.build(review_params)
|
308
|
+
|
309
|
+
if @review.save
|
310
|
+
|
311
|
+
flash[:success] = "口コミが投稿されました!"
|
312
|
+
|
313
|
+
redirect_to root_path
|
314
|
+
|
315
|
+
else
|
316
|
+
|
317
|
+
redirect_to root_path
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
```
|