self_or_other(消息)不起作用

时间:2015-07-11 01:03:18

标签: ruby-on-rails

我的应用程序运行良好,但当我尝试发送某人按摩时,我的消息回复无法正常工作给我错误“未定义方法`self_or_other'”。我不知道为什么它不起作用。

我的网页中出现的确切错误是:

  NoMethodError in Conversations#show

  Showing C:/Users/Arvind/project/book/app/views/messages/_message.html.erb    where line #1 raised:

 undefined method `self_or_other' for #<#<Class:0x667a1f0>:0x4fb6cd8>

 Trace of template inclusion: app/views/conversations/show.html.erb

 Rails.root: C:/Users/Arvind/project/book
 Application Trace | Framework Trace | Full Trace

  app/views/messages/_message.html.erb:1:in    `_app_views_messages__message_html_erb___30280179_42148572'
       app/views/conversations/show.html.erb:16:in  `_app_views_conversations_show_html_erb___631964137_59734080'

这是我的_message.html.erb看起来像这样

<li class="<%=  self_or_other(message) %>">
 <div class="avatar">
 <img src="http://placehold.it/50x50" />
  </div>
  <div class="chatboxmessagecontext">
  <p><%= message.body %></p>
   <time datetime="<%= message.created_at %>" title="<%= message.created_at.strftime("%d %b  %Y at %I:%M%p") %>">
    <%= message_interlocutor(message).full_name %> • <%= message.created_at.strftime("%H:%M %p") %>
     </time>
   </div>
 </li>

这是我的对话show_html.erb

 <div class="chatboxhead">
  <div class="chatboxtitle">
   <i class="fa fa-comments"></i>

  <h1><%= @reciever.full_name %> </h1>
  </div>
  <div class="chatboxoptions">
  <%= link_to "<i class='fa  fa-minus'></i> ".html_safe, "#", class: "toggleChatBox", "data-cid" => @conversation.id %>
&nbsp;&nbsp;
  <%= link_to "<i class='fa  fa-times'></i> ".html_safe, "#", class: "closeChat", "data-cid" => @conversation.id %>
  </div>
   <br clear="all"/>
   </div>
  <div class="chatboxcontext">
   <% if @messages.any? %>
  <%= render @messages %>
   <% end %>
</div>
    <div class="chatboxinput">
  <%= form_for([@conversation, @message], :remote => true, :html => {id: "conversation_form_#{@conversation.id}"}) do |f| %>
    <%= f.text_area :body, class: "chatboxtextarea", "data-cid" => @conversation.id %>
    <% end %>
  </div>

 <%= subscribe_to conversation_path(@conversation) %>

这是我的app / views / message / create.js.erb

  <% publish_to @path do %>
  <% broadcast "mesaage" do %>
   var id = "<%= @conversation.id %>";
   var chatbox = $("#chatbox_" + id + " .chatboxcontent");
   var sender_id = "<%= @message.user.id %>";
   var reciever_id = $('meta[name=user-id]').attr("context");

  chatbox.append("<%= j render( partial: @message ) %>");
  chatbox.scrollTop(chatbox[0].scrollHeight);

   if (sender_id != reciever_id) {
    chatBox.chatWith(id);
    chatbox.children().last().removeClass("self").addClass("other");
    chatbox.scrollTop(chatbox[0].scrollHeight);
    chatBox.notify();
  }
  <% end %>
 <% end %>

这是我的messages_helper.rb

  module MessagesHelper
   def self_or_other(message)
   message.user == current_user ? "self" : "other"
  end

 def message_interlocutor(message)
  message.user == message.conversation.sender ? message.conversation.sender : message.conversation.recipient
  end
end

谢谢!

0 个答案:

没有答案