進行中の会話のリストを各ユーザーに表示したいと考えています。そのため、クリックするだけで、必要な会話を表示できます。メールボックスの会話オブジェクトには ID がないため、このリンクの作成方法がわかりません。
このIDは通知オブジェクトに格納されているようですので、このオプションを試してみました。
このコードは、会話インデックス ビューからのものです。
<%all_conv = current_user.mailbox.conversations%>
<%all_conv.each do |participant|%>
<div class="ligne_conversation">
<ul>
<a href="conversations/<%=@conversation_id%>">
<li>
<%=image_tag participant.messages.last.sender.avatar.url(:thumb) %>
<%=participant.messages.last.sender.name%>
<%=participant.messages.last.body%>
</li>
</a>
</ul></div>
@conversation_id インスタンス変数は、会話コントローラーで定義されています
def index
if current_user.mailbox.conversations.any?
notification = Notification.find_by!(params[:id])
@conversation_id = notification.conversation_id
end
end
機能していません。すべてのリンクが id = 1 の会話につながっています。