Ruby on rails 使用render_async在rails中呈现新消息

Ruby on rails 使用render_async在rails中呈现新消息,ruby-on-rails,Ruby On Rails,我正在设置一个临时热修复程序,因为如果没有神秘的服务器破坏响应时间,我无法让ActionCable正常工作,并且需要一些帮助来理解文档。我的设置方式(我相信这与他们的建议一致)将整个页面呈现在div中,而不是在提交新消息时呈现新消息。我如何使它按我的意愿工作 routes.rb resources :conversations, only: [:index, :create], path: "chats" do resources :messages, only: [:index, :crea

我正在设置一个临时热修复程序,因为如果没有神秘的服务器破坏响应时间,我无法让ActionCable正常工作,并且需要一些帮助来理解文档。我的设置方式(我相信这与他们的建议一致)将整个页面呈现在div中,而不是在提交新消息时呈现新消息。我如何使它按我的意愿工作

routes.rb

resources :conversations, only: [:index, :create], path: "chats" do
 resources :messages, only: [:index, :create]
end
def index
 @conversations = Conversation.participating(current_user).order('updated_at DESC')
 @messages = @conversation.messages.all
 @message = @conversation.messages.new

 if !@conversation.unread_message_count(current_user).zero?
    @conversation.mark_as_read(current_user)
 end

 # render partial: "messages/message" 
 # (the docs suggest rendering the partial here, but i want it rendered in a div, not the entire window)
end
<%= render_async conversation_messages_path %>
<% @messages.each do |message| %>
    <% cache message do %>
        <div class="message">
            <div><strong><%= message.user.username %>:</strong> <%= message.body %></div>
            <div class="date"><%= local_time(message.created_at) %></div>
        </div>
    <% end %>
<% end %>
消息\u controller.rb

resources :conversations, only: [:index, :create], path: "chats" do
 resources :messages, only: [:index, :create]
end
def index
 @conversations = Conversation.participating(current_user).order('updated_at DESC')
 @messages = @conversation.messages.all
 @message = @conversation.messages.new

 if !@conversation.unread_message_count(current_user).zero?
    @conversation.mark_as_read(current_user)
 end

 # render partial: "messages/message" 
 # (the docs suggest rendering the partial here, but i want it rendered in a div, not the entire window)
end
<%= render_async conversation_messages_path %>
<% @messages.each do |message| %>
    <% cache message do %>
        <div class="message">
            <div><strong><%= message.user.username %>:</strong> <%= message.body %></div>
            <div class="date"><%= local_time(message.created_at) %></div>
        </div>
    <% end %>
<% end %>
messages/index.html.erb

resources :conversations, only: [:index, :create], path: "chats" do
 resources :messages, only: [:index, :create]
end
def index
 @conversations = Conversation.participating(current_user).order('updated_at DESC')
 @messages = @conversation.messages.all
 @message = @conversation.messages.new

 if !@conversation.unread_message_count(current_user).zero?
    @conversation.mark_as_read(current_user)
 end

 # render partial: "messages/message" 
 # (the docs suggest rendering the partial here, but i want it rendered in a div, not the entire window)
end
<%= render_async conversation_messages_path %>
<% @messages.each do |message| %>
    <% cache message do %>
        <div class="message">
            <div><strong><%= message.user.username %>:</strong> <%= message.body %></div>
            <div class="date"><%= local_time(message.created_at) %></div>
        </div>
    <% end %>
<% end %>

\u message.html.erb

resources :conversations, only: [:index, :create], path: "chats" do
 resources :messages, only: [:index, :create]
end
def index
 @conversations = Conversation.participating(current_user).order('updated_at DESC')
 @messages = @conversation.messages.all
 @message = @conversation.messages.new

 if !@conversation.unread_message_count(current_user).zero?
    @conversation.mark_as_read(current_user)
 end

 # render partial: "messages/message" 
 # (the docs suggest rendering the partial here, but i want it rendered in a div, not the entire window)
end
<%= render_async conversation_messages_path %>
<% @messages.each do |message| %>
    <% cache message do %>
        <div class="message">
            <div><strong><%= message.user.username %>:</strong> <%= message.body %></div>
            <div class="date"><%= local_time(message.created_at) %></div>
        </div>
    <% end %>
<% end %>



嘿,当你使用你发布的代码时,你看到了什么?是正确加载索引页还是发生了什么?另外,我是gem的作者和维护者,如果您仍然有问题,我可以帮助您。@NikolaĐuza感谢您的跟进,但我应该结束这个问题!原来我不需要宝石。Heroku的Logentries插件将OpenWebSockets连接错误标记为高响应时间错误,ActionCable的基本设置工作正常。收到了,感谢回复!嘿,当你使用你发布的代码时,你看到了什么?是正确加载索引页还是发生了什么?另外,我是gem的作者和维护者,如果您仍然有问题,我可以帮助您。@NikolaĐuza感谢您的跟进,但我应该结束这个问题!原来我不需要宝石。Heroku的Logentries插件将OpenWebSockets连接错误标记为高响应时间错误,ActionCable的基本设置工作正常。收到了,感谢回复!