0

在我添加刺激反射宝石来发布和取消发布帖子之前,我的项目运行良好。当我刷新服务器自行停止。

这是来自服务器

C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/redis-4.3.1/lib/redis/client.rb:382:in `rescue in establish_connection': Error connecting to Redis on localhost:6379 (Redis::TimeoutError) (Redis::CannotConnectError)

这是我的 edit.html.erb

    <div class="card-footer">
            <% if @post.published? %>
            <a href="#" class="btn btn-warning col-12"
            data-reflex='click->PublisherReflex#unpublish'
            data-post-id='<%= @post.id %>'>
            Unpublish
          </a>
            <% else %>
            <a href="#" class="btn btn-dark col-12"
            data-reflex='click->PublisherReflex#publish'
            data-post-id='<%= @post.id %>'>
            Publish
          </a>
            <%end%>
          </div>

这是 publisher_reflex.rb

    def publish
      post = Post.find(element.dataset[:post_id])
      post.update(published: true, published_at: Time.now)
    end
    
    def unpublish
      post = Post.find(element.dataset[:post_id])
      post.update(published: false, published_at: nil)
    
    end

这是我的 cable.yml

development:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: ngong_municipality_development

test:
  adapter: test

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: ngong_municipality_production
4

0 回答 0