我安装了private_pub并编码。问题是当我按下发送按钮时,我实现private_pub的页面没有更新。我看着控制台,但没有错误。这是我的代码。 消息/ _message.html.erb
ModelAttribute

消息/ create.js.erb
<div class="row">
<div class="col-md-8 col-md-offset-2 message_container">
<div class="message_img_container pull-left">
<%= image_tag message.user.avatar.url(:thumb), class:"message_img" if message.user.present?%>
</div>
<div>
<div class="message_user">
<% if message.user.present? %>
<% full_name = message.user.last_name << message.user.first_name %>
<%= link_to full_name, '#', class:""%>
<span> ー<%= message.user.college %> <span>
<% end %>
</div>
<div class="message_comment">
<%= message.comment %>
</div>
</div>
</div>
</div>
&#13;
消息/ index.html.erb
<% publish_to '/themes/#{@theme}/messages' do %>
$('#chat').append("<%= j render @messages %>");
<% end %>
$('#new_message')[0].reset();
&#13;
messages_controller.rb
<div class="col-md-8 col-md-offset-2">
<div>
<h1><%= @theme.title %></h1>
</div>
</div>
<div id="chat">
<% @messages.each do |message| %>
<%= render 'messages/message', message: message %>
<% end %>
</div>
<div class="row comment_container">
<div class="col-md-8 col-md-offset-2">
<%= form_for [@theme, @theme.messages.new], remote: true do |f| %>
<div class="form-group ">
<%= f.label :comment,'コメント'%>
<%= f.text_area :comment, class:'form-control' %>
</div>
<%= f.submit 'POST'%>
<% end %>
</div>
</div>
<% content_for :bottom do %>
<%= subscribe_to '/themes/#{@theme}/messages' %>
<% end %>
&#13;
(主题有很多消息,消息属于主题。消息索引页面的URL是themes / theme_id / messages。
对不起我可怕的英语...... 希望有人帮助我谢谢这是pribate_pub.yml
class MessagesController < ApplicationController
before_action :current_user
before_action :require_user
before_action :set_theme
def index
@theme = Theme.find(params[:theme_id])
@messages = @theme.messages.all
end
def create
@message = @theme.messages.new(message_params)
@message.user = current_user
@messages = @theme.messages
if @message.save
respond_to do |format|
format.js
end
else
flash[:danger] = "Something wrong ??????"
end
end
private
def set_theme
@theme = Theme.find(params[:theme_id])
end
def message_params
params.require(:message).permit(:comment)
end
end