I installed private_pub and coded. The problem is that the page I implemented private_pub doesn't update when I press send-button. I looked into console, but there was no error. Here is my code. messages/_message.html.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>
messages/create.js.erb
<% publish_to '/themes/#{@theme}/messages' do %>
$('#chat').append("<%= j render @messages %>");
<% end %>
$('#new_message')[0].reset();
messages/index.html.erb
<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 %>
messages_controller.rb
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
(theme has many messages and a message belongs to theme. URL of messages index page is themes/theme_id/messages.
sorry for my terrible english... hope someone help me thanks
this is pribate_pub.yml
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "http://example.com/faye"
secret_token: " "
signature_expiration: 3600 # one hour