【问题标题】:Mailboxer: recipient inbox not showing conversations邮箱:收件人收件箱不显示对话
【发布时间】:2017-06-07 15:55:36
【问题描述】:

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

<%= 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 %>

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

/conversations/new?recipient_id=7

使用正确用户ID的ID,但是当我发送消息时,

我有以下错误:

could'n find user with 'id'=

【问题讨论】:

  • 当您说用户7的会话页面时,您是指会话show.html.erb吗?
  • 不,我的意思是在对话页面的索引上。我认为问题属于收件人未正确关联,因为在发件人对话索引上,您可以看到对话

标签: ruby-on-rails mailboxer


【解决方案1】:

我终于让它工作了,这是我的代码,也许它可以帮助其他人:

(我在 5 号轨道上)

我的产品页面上的链接:

<%= 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}") %>

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 2010-09-23
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多