私は、経路:リソースである会話と部分的に会話していますが、ナビゲーションバーにこの部分をレンダリングしようとすると(アクティブな会話をすべて表示します)あなたのレールアプリのどこにでも部分をレンダリングする
undefined method `author' for nil:NilClass
は、今私は
どこでもあなたのウェブサイト上であなたのパーシャルをレンダリングするための特別な方法はあり<%= render 'conversations/conversation' %>
をやっていますか?
EDIT:コード
会話/ _conversation.html.erb
<div>
From <strong><%= conversation.author.email %></strong> to
<strong><%= conversation.receiver.email %> (<%#= conversation.receiver.online? ? 'online' : 'offline' %>)</strong>
<br>
<%= link_to 'View conversation', conversation_path(conversation) %>
<hr>
</div>
レイアウト/ _navigation.html.erb
<%= render 'conversations/conversation' %>
経路
#Chat
resources :conversations
resources :personal_messages
resources :users
mount ActionCable.server => '/cable'
EDIT2を提供
conversations_controller.rb
class ConversationsController < ApplicationController
before_action :set_conversation
before_action :check_participating!, except: [:index]
def index
@conversations = Conversation.participating(current_user).order('updated_at DESC')
respond_to do |format|
format.html
format.js
end
end
def show
@personal_message = PersonalMessage.new
@conversations = Conversation.participating(current_user)
end
private
def set_conversation
@conversation = Conversation.find_by(id: params[:id])
end
def check_participating!
redirect_to root_path unless @conversation && @conversation.participates?(current_user)
end
end
ApplicationControllerに
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate_user!
end
コードを入力できますか? –
どのような方法が定義されていませんか? – Bek
レンダリング部分: '会話/会話'、地元民:{会話:会話}? – Mingsheng