jQuery插件不工作Rails 5
Raty jQuery plugin not working Rails 5
我是RoR的新手,我在应用程序上显示Raty插件时遇到了问题。此外,我注意到另一个Js函数已经停止工作,因为我已经添加了Raty,所以我相信他们之间有冲突?
已经添加了Raty对应文件:jquery.raty.js//jquery.raty.css//images
所有的帮助将是感激的,谢谢!
/模型/product.rb
def average_rating
comments.average(:rating).to_f
end
/资产/javascript/application.js
$(document).on('turbolinks:load', function () {
$(".alert").delay(1500).fadeOut("slow");
});
$(document).on('turbolinks:load', function () {
$(".notice").delay(1500).fadeOut("slow");
});
/资产/javascript/site.js
$(document).on('turbolinks:load', function(){
$('.rating').raty( { path: '/assets', scoreName: 'comment[rating]' });
$('.rated').raty({ path: '/assets',
readOnly: true,
score: function() {
return $(this).attr('data-score');
}
});
});
/视图/产品/_new_comment.erb
<% if signed_in? %>
<h2>Add a review:</h2>
<%= form_for([@product, @product.comments.build]) do |f| %>
<p>
<%= f.label :body, "Comments" %><br>
<%= f.text_area :body %>
</p>
<p>
<%= f.label :rating, "Rating" %><br>
<div class="rating"></div>
</p>
<br>
<p>
<%= f.submit "Submit" %>
</p>
<% end %>
<% end %>
/视图/产品/_comments.erb
<div class="product-reviews">
<% @comments.each do |comment| %>
<div class="row">
<hr>
<p><%= comment.user.first_name %> <small><em><%= "#{time_ago_in_words(comment.created_at)} ago" %></em></small></p>
<p><div class="rated" data-score="<%= comment.rating %>"></div></p>
<p><%= comment.body %></p>
</div>
<% end %>
</div>
/视图/产品/show.html.erb
<div class="col-md-12">
<%= render partial:'new_comment' %>
</div>
<div class="col-md-12">
<%= render partial:'comments' %>
</div>
你没有在你的问题中复制你的config/environments/production.rb
,但它可能看起来像这样:config.assets.compile = false
如果你把它改为true,它应该可以工作:config.assets.compile = true
相关文章:
- Rails-JQueryUIAutcomplete和AJAX不工作,可以't连接到数据库
- 引导程序转盘不工作:堆叠图像(使用rails)
- 为什么Turbolinks不能正常工作?Rails应用程序
- Rails Production-可以工作,但不能编辑/删除/创建记录
- escape_javascript无法在rails 3.2.7中工作
- 地图,rails 4.2,javascript,鼠标悬停,只工作一次(或两次).然后在重新加载之后
- Rails JQuery和Ajax对我来说工作不正常
- 为什么不是't在我的rails部分中工作的DataTables
- Rails页面JS可以在真正的浏览器/手动测试中工作,但不能在PhantomJS&硒规格
- 如何让手图在 Rails 中工作
- Rails 应用程序中不显眼的 JS 无法按预期工作
- rails 预编译 为什么 javascript 在本地不起作用,但在 heroku 它可以工作
- Rails 3.2.3 JavaScript 突然停止工作
- Javascript文件只能在Rails应用程序中按字母顺序工作
- 如何让 AJAX 使用 rails 和 JavaScript 计时器工作
- 自动关闭引导警报在 Rails 中停止工作
- Rails 4:资产管道的正常CSS/JS开发工作流程
- Rails 4 Ajax 调用只工作一次
- Rails 4 turbo-link 阻止 jQuery 脚本工作
- Rails 应用程序 - jQuery Document.ready在单击链接时不调用,但在新选项卡中打开或刷新时工作