我有这样的帮手链接如何显示的link_to助手仅当它返回> 0
link_to "", product_path(product, anchor: "disqus_thread"), data: { "disqus-identifier" => "#{url_for([product, {only_path: false}])}" }, class: "no-underline bold grey-text text-darken-3 margin-left"
布局:application.rb中
%script{id: "dsq-count-scr", src: "https://url.disqus.com/count.js", async: "async"}
_disqus.html.erb
<div class="col-lg-8 col-lg-offset-2 big-top-space margin-bottom">
<div id="disqus_thread"></div>
<script>
var disqus_shortname = 'yourname';
var disqus_identifier = '<%= url_for([product, {only_path: false}]) %>';
var disqus_title = '<%= product.name %>';
var disqus_url = '<%= url_for([product, {only_path: false}]) %>';
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://url.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
和所有工作正常我得到一个数字,数量是在我的索引视图中每个职位的disqus评论计数器,但如何显示数字如果是否大于0?如果等于0我不想在视图中显示它。有人知道如何解决这个问题?非常感谢
我试着用这样的:
此列添加到产品COMMENT_COUNT:整数
我改变了我的_disqus.html
<div class="col-lg-8 col-lg-offset-2 big-top-space margin-bottom">
<div id="disqus_thread"></div>
<script>
var disqus_shortname = 'yourname';
var disqus_identifier = '<%= url_for([product, {only_path: false}]) %>';
var disqus_title = '<%= product.name %>';
var disqus_url = '<%= url_for([product, {only_path: false}]) %>';
var disqus_config = function() {
this.callbacks.onNewComment = [
function() {
$.ajax({
method: "PATCH",
url: '<%= product_path(product) %>',
data: {increment: "comment_count"}
})
}
];
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://url.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
Product_controller
def update
product = Product.find(params[:id])
product.update(update_product)
end
def update_product
params.permit(:comment_count)
end
,但我得到这个错误
Started PATCH "/products/12" for ::1 at 2017-04-12 17:44:38 -0500
Processing by ProductsController#update as */*
Parameters: {"increment"=>"comment_count", "id"=>"12"}
ShoppingCart Load (0.0ms) SELECT "shopping_carts".* FROM "shopping_carts" WH
ERE "shopping_carts"."id" = ? LIMIT 1 [["id", 102]]
Product Load (0.0ms) SELECT "products".* FROM "products" WHERE "products"."i
d" = ? LIMIT 1 [["id", 12]]
CACHE (0.0ms) SELECT "products".* FROM "products" WHERE "products"."id" = ?
LIMIT 1 [["id", "12"]]
Unpermitted parameters: increment, id
(0.0ms) begin transaction
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT
1 [["id", 1]]
(0.0ms) commit transaction
Rendered products/update.haml within layouts/application (0.0ms)
(0.0ms) SELECT COUNT(*) FROM "products" INNER JOIN "in_shopping_carts" ON "p
roducts"."id" = "in_shopping_carts"."product_id" WHERE "in_shopping_carts"."shop
ping_cart_id" = ? [["shopping_cart_id", 102]]
Rendered partials/_unlogged.haml (15.5ms)
Rendered partials/_nav.haml (765.8ms)
Completed 200 OK in 3476ms (Views: 3448.8ms | ActiveRecord: 0.0ms)
控制台不允许的参数:增量,ID
COMMENT_COUNT:无
有人能帮助我吗?
你如何恢复disqus评论柜台?你有模型方法吗? –
我在applicationacion.layout%script {id:“dsq-count-scr”,src:“https://urlyoururl.disqus.com/count.js”,async:“async”}中获得了这个脚本 –
我不认识那个代码,请提供该脚本的更多细节(关于这个问题)。 –