2
我想爲每個用戶顯示正在進行的會話列表。所以他們可以點擊它並顯示他們想要的對話。由於郵箱中的對話對象沒有ID,因此我無法找到如何建立此鏈接。郵箱:如何顯示特定的會話?
這個ID似乎存儲在通知對象,所以我試過這個選項。
來自談話索引視圖
<%all_conv = current_user.mailbox.conversations%>
<%all_conv.each do |participant|%>
<div class="ligne_conversation">
<ul>
<a href="conversations/<%[email protected]_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.
感謝您的回答,它工作。我忘了提及我已經在我的show動作中添加了'@conversation = Conversation.find(params [:id])''。我誤解了(也許仍然)如何找到這個特殊的ID。你是對的:這是我的一些教程時間後的第一個應用程序。我會遵循你的建議,我有很多東西要學會它不會受到傷害。 – Ruff9
http://www.railscasts.com是許多知識的絕佳來源,其中許多教程都是免費提供的。瑞恩貝茨的頂級視頻。 –