1

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
  • Is Faye server running standalone? If not - how did you mount the engine and which rack server is used? – Vasfed Jan 28 '16 at 08:28
  • I am using Nitrous IDE and did rackup private_pub.ru -s thin -E production on console so I think faye is running – 黒田宏樹 Jan 28 '16 at 09:17
  • Also I realize that $('#new_message')[0].reset(); in create.js.erb file is executed because text disappears after i pressed send-button – 黒田宏樹 Jan 28 '16 at 09:23
  • That shows that button press event reaches rails, but still does not ensure that Faye message gets sent and delivered – Vasfed Jan 28 '16 at 09:26
  • I did not know that..... I think it is localhost 9292 if this answers your question – 黒田宏樹 Jan 28 '16 at 12:06
  • Please show your `private_pub.yml` (but replace `secret_token` to not disclose it) – Vasfed Jan 28 '16 at 12:10

0 Answers0