简体   繁体   English

邮箱:在产品页面上创建指向新会话的链接

[英]Mailboxer: creating link to new conversation on a product page

I am working on a marketplace. 我正在市场上工作。 I have a page with all the products. 我有一个包含所有产品的页面。

I want to create a link on each of this product, to allow user to send message to the seller, creating a new conversation. 我想在每个产品上创建一个链接,以允许用户向卖家发送消息,创建新的对话。

I am thinking about creating a link with that: 我正在考虑创建一个链接:

<%= link_to "Contactar", new_conversation_path %>

But can i put in this link the recipient directly ? 但我可以直接在这个链接中加入收件人吗?

If yes, what should i change in the conversation_controller ? 如果是,我应该在conversation_controller中更改什么?

def new
  recipients = Product.where(user: params[:user_id])
end

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

But can i put in this link the recipient directly ? 但我可以直接在这个链接中加入收件人吗?

Yes! 是! You can pass the individual recipient id directly in the link like below 您可以直接在下面的链接中传递单个收件人ID

<%= link_to "Contactar", new_conversation_path(recipient_id: @your_recipient.id %>

And access the recipient's id with params[:recipient_id] in the new method. 并使用方法中的params[:recipient_id]访问收件人的ID

Here is what i finally written: 这是我最后写的:

On my product listing 在我的产品列表中

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

In the conversations_controller: 在conversations_controller中:

def new

@recipient = params[:recipient_id]
end

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

So now on the conversation new page, the url show: /conversations/new?recipient_id= 所以现在在对话新页面上,网址显示:/ conversations / new?recipient_id =

thanks @Pavan 谢谢@Pavan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM