質問編集履歴
5
kuchikomi.jsの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -200,6 +200,37 @@
|
|
200
200
|
end
|
201
201
|
```
|
202
202
|
|
203
|
+
kuchikomi.js
|
204
|
+
```
|
205
|
+
// Place all the behaviors and hooks related to the matching controller here.
|
206
|
+
// All this logic will automatically be available in application.js.
|
207
|
+
|
208
|
+
// jQuery Plugin. Set/show rating by star
|
209
|
+
function initRaty() {
|
210
|
+
if($('.raty-read').length) {
|
211
|
+
$('.raty-read').raty({
|
212
|
+
starType: 'i',
|
213
|
+
space: false,
|
214
|
+
readOnly: true,
|
215
|
+
score: function() { return $(this).data('rating') }
|
216
|
+
})
|
217
|
+
}
|
218
|
+
|
219
|
+
if($('.raty').length) {
|
220
|
+
$('.raty').raty({
|
221
|
+
starType: 'i',
|
222
|
+
target: 'dounan_kuchikomi', // Sync rating to #dounan_kuchikomi
|
223
|
+
targetKeep: true,
|
224
|
+
targetType: 'number',
|
225
|
+
space: true,
|
226
|
+
score: function() { return $(this).data('rating') }
|
227
|
+
})
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
$(document).on('load turbolinks:load', initRaty)
|
232
|
+
```
|
233
|
+
|
203
234
|
参照
|
204
235
|
[https://qiita.com/nekonoprotocol/items/4bc5bd9c64dc3f181016](https://qiita.com/nekonoprotocol/items/4bc5bd9c64dc3f181016)
|
205
236
|
[https://qiita.com/kitaokeita/items/1e40724c3384507cec13](https://qiita.com/kitaokeita/items/1e40724c3384507cec13)
|
4
参考リポジトリの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -204,9 +204,13 @@
|
|
204
204
|
[https://qiita.com/nekonoprotocol/items/4bc5bd9c64dc3f181016](https://qiita.com/nekonoprotocol/items/4bc5bd9c64dc3f181016)
|
205
205
|
[https://qiita.com/kitaokeita/items/1e40724c3384507cec13](https://qiita.com/kitaokeita/items/1e40724c3384507cec13)
|
206
206
|
|
207
|
-
試したこと
|
207
|
+
**試したこと**
|
208
208
|
[http://gouf.hatenablog.com/entry/2018/02/05/003548](http://gouf.hatenablog.com/entry/2018/02/05/003548)
|
209
209
|
を参考に、```dounan_kuchikomi_new.html.erb```で、星評価の機能を実装
|
210
210
|
|
211
|
+
参考リポジトリ
|
212
|
+
[https://github.com/wbotelhos/raty](https://github.com/wbotelhos/raty)
|
213
|
+
[https://github.com/gouf/rails_raty_demo](https://github.com/gouf/rails_raty_demo)
|
211
214
|
|
215
|
+
|
212
216
|
付けた星の数を、そのまま```dounan_kuchikomi.html.erb```に反映させる方法を、ネットで検索しても出てこないので、ご教示お願いできませんでしょうか?
|
3
試したことを記入
title
CHANGED
File without changes
|
body
CHANGED
@@ -204,5 +204,9 @@
|
|
204
204
|
[https://qiita.com/nekonoprotocol/items/4bc5bd9c64dc3f181016](https://qiita.com/nekonoprotocol/items/4bc5bd9c64dc3f181016)
|
205
205
|
[https://qiita.com/kitaokeita/items/1e40724c3384507cec13](https://qiita.com/kitaokeita/items/1e40724c3384507cec13)
|
206
206
|
|
207
|
+
試したこと
|
208
|
+
[http://gouf.hatenablog.com/entry/2018/02/05/003548](http://gouf.hatenablog.com/entry/2018/02/05/003548)
|
209
|
+
を参考に、```dounan_kuchikomi_new.html.erb```で、星評価の機能を実装
|
207
210
|
|
211
|
+
|
208
212
|
付けた星の数を、そのまま```dounan_kuchikomi.html.erb```に反映させる方法を、ネットで検索しても出てこないので、ご教示お願いできませんでしょうか?
|
2
ビューの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,10 +22,11 @@
|
|
22
22
|
<li class="media">
|
23
23
|
<h2>レビューを投稿する</h2>
|
24
24
|
<%= form_for ([@dounan, @dounan_kuchikomi]) do |f| %>
|
25
|
-
<div class="field" id="star">
|
26
|
-
|
25
|
+
<%= f.label :rate, '評価' %>
|
26
|
+
<%= tag.div('', class: 'raty', data: { rating: @dounan_kuchikomi.rate }) %>
|
27
|
+
<!-- this hidden field will manipulated by raty-js
|
28
|
+
/ See: app/assets/javascripts/kuchikomis.js -->
|
27
|
-
|
29
|
+
<%= f.hidden_field :rate %>
|
28
|
-
</div>
|
29
30
|
<%= f.label :title, '題名' %>
|
30
31
|
<%= f.text_field :title, class: 'form-control', rows: 5 %>
|
31
32
|
<%= f.label :picture, '写真' %>
|
1
本文修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
☆評価を付けて口コミを投稿
|
6
6
|
|
7
7
|
**問題点**
|
8
|
-
星を、5段階評価で最高の5個を付けたにも拘らず、ビュー画面では0になっている。
|
8
|
+
星を、5段階評価で最高の5個を付けたにも拘らず、口コミ投稿後のビュー画面では0になっている。
|
9
9
|
[https://gyazo.com/929c1dcd7ae4e2c1222ecb9bd0559bb4](https://gyazo.com/929c1dcd7ae4e2c1222ecb9bd0559bb4)
|
10
10
|
|
11
11
|
該当コード
|