質問編集履歴
2
開発環境を追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
###前提・分からないこと
|
2
|
+
|
3
|
+
開発環境:Ruby on Rails 5.0.0.1
|
4
|
+
|
2
5
|
Ruby(RubyonRails)で食べログのようなレビューサイトを作成しています。
|
3
6
|
レストランの詳細ページ上で『レビュー登録ボタン』を設置し、モーダル登場でレビュー登録ができるようにしようと考えています。
|
4
7
|
|
1
コントローラー、ビューのコードを変更しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -92,4 +92,73 @@
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
|
+
```
|
96
|
+
|
97
|
+
###追記分
|
98
|
+
|
99
|
+
変更してやってみたのですが、なかなかうまくいきません(涙
|
100
|
+
ビューは表示されるのですが、f.submitを押しても一切動かないのです!(T_T)
|
101
|
+
|
102
|
+
・ビュー
|
103
|
+
|
104
|
+
```Ruby
|
105
|
+
・・・
|
106
|
+
<!-- Modal -->
|
107
|
+
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="z-index: 30000;">
|
108
|
+
<div class="modal-dialog" role="document">
|
109
|
+
<div class="modal-content">
|
110
|
+
<%= form_for(@review) do |f| %>
|
111
|
+
<%= render 'shared/error_messages', object: f.object %>
|
112
|
+
<div class="modal-body">
|
113
|
+
<div class="title page-form account-form">
|
114
|
+
<h2>口コミを登録する</h2>
|
115
|
+
<form>
|
116
|
+
<div class="form-group review-form-restaurant">
|
117
|
+
<h3><%= @restaurant.name %></h3>
|
118
|
+
<%= f.hidden_field :restaurant_id, :value => @restaurant.id %>
|
119
|
+
</div>
|
120
|
+
<div class="form-group">
|
121
|
+
<label for="exampleInputName">口コミを入力する</label><br />
|
122
|
+
<%= f.select :rate, {'1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5,}, class: "form-control" %>
|
123
|
+
</div>
|
124
|
+
<div class="form-group">
|
125
|
+
<%= f.text_field :title, class: "form-control", placeholder: "タイトル" %>
|
126
|
+
</div>
|
127
|
+
<div class="form-group">
|
128
|
+
<%= f.text_area :content, class: "form-control", placeholder: "口コミ内容", rows: "5" %>
|
129
|
+
</div>
|
130
|
+
</form>
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
<div class="modal-footer">
|
134
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">閉じる</button>
|
135
|
+
<%= f.submit "投稿する", class: "btn btn-form btn-modal" %>
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
<% end %>
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
・・・
|
142
|
+
```
|
143
|
+
|
144
|
+
・コントローラー(restaurant)
|
145
|
+
```Ruby
|
146
|
+
class RestaurantsController < ApplicationController
|
147
|
+
before_action :logged_in_user, only: :create
|
148
|
+
|
149
|
+
def show
|
150
|
+
@review = current_user.reviews.build if logged_in?
|
151
|
+
end
|
152
|
+
|
153
|
+
def create
|
154
|
+
@review = current_user.reviews.build(review_params)
|
155
|
+
if @review.save
|
156
|
+
flash[:success] = "口コミが投稿されました!"
|
157
|
+
redirect_to root_path
|
158
|
+
else
|
159
|
+
redirect_to root_path
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
95
164
|
```
|