counter_cache没有在ajax中更新

我有一个运行类似链接的js代码(带有ajax) – 链接更改为不同(使用正确的路由和方法),并且我希望也更新模型中的列的likes_count。

问题是价值没有得到更新。 没有Ajax(整页加载) – 值正常

#create.js.erb $("#like_link").html("") $("#likes").html('') #relevant html snippet from the view 
Total likes:
#model - like.rb class Like true end

使用时
$("#likes").html('')
它工作但缺少counter_cache的观点

在你的create方法中,在保存对象之后,你应该reload你喜欢的对象,如下所示:

 def create # some code if @like.save @artwork.reload # use reload to get the updated counter cache value end end