动作电缆数据在heroku上无法正确显示

时间:2018-06-09 04:36:13

标签: javascript ruby-on-rails heroku actioncable

我在heroku上遇到动作电缆问题。操作电缆正常工作正在广播更新,但是每当我从系统执行任何更新时,数据似乎都是缓存。

情况:

db sample(在postgres上):

产品has_many项目

  1. 用户更新产品并删除其中一个项目
  2. 更新显示页面上的记录后,它仍会显示已删除的项目。然而,在我刷新它之后再次。我再次刷新它再次回来似乎记录被缓存,它随机回来。它发生在应用程序的所有记录中。
  3. 但是,如果我移除动作电缆(带有redis),它可以正常工作。更新工作正常。
  4. 它在本地唯一的heroku制作问题上运行正常。它随机出现(每次重新加载页面时都会改变)

    以下是我的文件:

    宝石:

    
    
    ruby "2.3.1"
    gem 'puma', '~> 3.9', '>= 3.9.1'
    gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
    gem 'redis', '~> 3.3', '>= 3.3.3'
    
    
    

    cable.yml

    
    
    development:
      adapter: redis
      url: redis://localhost:6379/1
    
    test:
      adapter: async
    
    production:
      adapter: redis
      url: <%= ENV["REDIS_URL"] %>
    &#13;
    &#13;
    &#13;

    &#13;
    &#13;
    // Action Cable provides the framework to deal with WebSockets in Rails.
    // You can generate new channels where WebSocket features live using the rails generate channel command.
    //
    //= require action_cable
    //= require_self
    //= require_tree ./channels
    
    (function() {
      this.App || (this.App = {});
    
      App.cable = ActionCable.createConsumer();
    
    }).call(this);
    &#13;
    &#13;
    &#13;

    信道/ connection.rb

    &#13;
    &#13;
    module ApplicationCable
      class Connection < ActionCable::Connection::Base    
        identified_by :current_user
    
        def connect
          self.current_user = find_verified_user
        end
    
        private
          def find_verified_user
            verified_user = User.find_by(id: cookies.signed['user.id'])
            if verified_user
              verified_user
            else
              reject_unauthorized_connection
            end
          end
      end
    end
    &#13;
    &#13;
    &#13;

    信道/ web_notifications_channel.rb

    # channel/web_notifications_channel.rb
    
    class WebNotificationsChannel < ApplicationCable::Channel
      def subscribed
        stream_from "web_notifications_#{current_user.id}"
      end
    
      def unsubscribed
        # Any cleanup needed when channel is unsubscribed
      end
    
      def speak(data)
      end
    
    end
    

0 个答案:

没有答案
相关问题