如何在Rails中使用Jquery Raty存储来自星级评定的多个值
我正在构建一个应用程序,用户可以根据一组标准对列表进行评分 我希望用户能够给每个属性打分1-5颗星 例如: 位置(1-5颗星) 物有所值(1-5颗星) 等等 我现在有一个简单的表单,看起来像这样如何在Rails中使用Jquery Raty存储来自星级评定的多个值,jquery,ruby-on-rails,Jquery,Ruby On Rails,我正在构建一个应用程序,用户可以根据一组标准对列表进行评分 我希望用户能够给每个属性打分1-5颗星 例如: 位置(1-5颗星) 物有所值(1-5颗星) 等等 我现在有一个简单的表单,看起来像这样 <%= simple_form_for([@stadium, @rating]) do |f| %> <label>Rate the Location:</label> <div class="rating-location"> </div>
<%= simple_form_for([@stadium, @rating]) do |f| %>
<label>Rate the Location:</label>
<div class="rating-location">
</div>
<label>Rate the value for the money:</label>
<div class="rating-monetary-value">
</div>
...
<div class="actions">
<%= f.button :submit, "Submit Rating", class:'btn btn-success' %>
</div>
<% end %>
对位置进行评级:
评估货币价值:
...
$(“.评级位置”).raty({
路径:'/assets/',
scoreName:“评级[位置]”,
提示:[“差”、“差”、“一般”、“好”、“漂亮”]
});
这会将位置分级保存到“我的分级”表中的“位置”列中
但我不确定如何继续,以便将多个值保存到同一个表中。例如货币价值评级和其他评级属性)。总共有8种不同的属性可供用户评分
我不熟悉Rails和Jquery,正在努力学习。任何帮助都将不胜感激。我遇到了与您类似的问题。我的解决方法是为每个属性创建单独的id,并在js脚本中创建单独的raty调用。因此,在你的情况下:
<label>Rate the Location:</label>
<div id="rating-location"></div>
<label>Rate the Monetary Value:</label>
<div id="rating-monetary-value"></div>
<script>
$('#rating-location').raty({
path: '/assets/',
scoreName: 'rating[location]',
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous']
});
$('#rating-monetary-value').raty({
path: '/assets/',
scoreName: 'rating[monatery-value]',
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous']
});
</script>
对位置进行评分:
对货币价值进行评级:
$(“#评级位置”).raty({
路径:'/assets/',
scoreName:“评级[位置]”,
提示:[“差”、“差”、“一般”、“好”、“漂亮”]
});
美元(“#评级货币价值”).raty({
路径:'/assets/',
scoreName:“评级[单目值]”,
提示:[“差”、“差”、“一般”、“好”、“漂亮”]
});
这看起来像是大量的代码重复(我有大约10个属性),但它现在可以工作了
您还可以使用gem“ratyrate”,它将允许您指定模型中的每个属性:
<label>Rate the Location:</label>
<div id="rating-location"></div>
<label>Rate the Monetary Value:</label>
<div id="rating-monetary-value"></div>
<script>
$('#rating-location').raty({
path: '/assets/',
scoreName: 'rating[location]',
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous']
});
$('#rating-monetary-value').raty({
path: '/assets/',
scoreName: 'rating[monatery-value]',
hints: ['bad', 'poor', 'regular', 'good', 'gorgeous']
});
</script>