0

以下代码在推送新事件时很好地更新了我的页面,但是当要求函数“current_msuser.countunread”从数据库中获取结果时,在这种情况下是记录计数,计数不会更新......

这个问题在开发和生产环境中都是一样的。

HTML CODE
<script>
    var pusher = new Pusher('xxx');
    var channel = pusher.subscribe('announcements');
    channel.bind('new-one', function(data) {
        xxx = "<%= current_msuser.countunread %>";
    document.getElementById("load-new-latest").innerHTML=xxx;
});
</script>

<a href="#" id="load-new-latest"><%= current_msuser.countunread %></a>

RUBY ACTIVERECORD CLASS

class Msuser < ActiveRecord::Base

    def countunread
        "#{Announcement.all.count.to_words remove_hyphen: true} new stories"
    end
end

THE PUSH NOTIFICATION IS SENT BY ...

class Announcement < ActiveRecord::Base 

    after_create :pusher_notify

    private

    def pusher_notify
        Pusher.app_id = 'xxx'
        Pusher.key = 'xxx'
        Pusher.secret = 'xxx'    

        Pusher['announcements'].trigger('new-one', {:message => self.message})
    end

 end

任何想法为什么会这样将不胜感激。

4

0 回答 0