ruby-on-rails Mailboxer:收件人收件箱不显示对话

bkkx9g8r  于 2023-10-21  发布在  Ruby
关注(0)|答案(1)|浏览(137)

在我的市场的产品列表页面上,我创建了一个按钮,向每个产品的用户发送消息,链接为:

<%= link_to "Contact", new_conversation_path(recipient_id: product.user.id) %>

下面是我的converations_controller:

class ConversationsController < ApplicationController
before_action :authenticate_user!


def index
@conversations = current_user.mailbox.conversations
end

def show
@conversation = current_user.mailbox.conversations.find(params[:id])
end

def new

 
@recipient = User.find(params[:recipient_id])
end

def create
recipient = User.find(params[:recipient_id]).id
receipt = current_user.send_message(@recipient, params[:body], params[:subject])
redirect_to conversation_path(receipt.conversation)
end

end

我的新对话页:

<h1>New conversation</h1>

<%= form_tag conversations_path, method: :post do %>
<div>

</div>

<div>
<%= text_field_tag :subject, nil, placeholder: "Subject" %>
</div>

<div>
<%= text_area_tag :body, nil, placeholder: "Your message" %>
</div>

<%= submit_tag "Send",:class=>"btn btn-warning" %>

<% end %>

当我点击链接发送消息时,我会正确地重定向到“新对话”页面,其URL上有:

/conversations/new?recipient_id=7

但当我发送消息时,
我有以下错误:
找不到具有“id”的用户=

utugiqy6

utugiqy61#

我终于让它工作了,这是我的代码,也许它可以帮助其他:
(我在铁轨上)
我的产品页面上的链接:

<%= link_to "Contactar", new_conversation_path(recipient_id: service.user.id) %>

我的对话控制器上的新建和创建操作:

def new
 @recipients = User.find(params[:recipient_id])

 end

 def create
 recipient = User.find_by(id: params[:recipient_id])
 receipt = current_user.send_message(recipient, params[:body],    params[:subject])
 redirect_to conversation_path(receipt.conversation)
 end

关于新的对话:

<%= hidden_field_tag(:recipient_id, "#{@recipients.id}") %>

相关问题