Mailboxer:在产品页面上创建 link 新对话
Mailboxer: creating link to new conversation on a product page
我在市场上工作。
我有一个包含所有产品的页面。
我想在每个产品上创建一个 link,以允许用户向卖家发送消息,创建一个新的对话。
我正在考虑用它创建一个 link:
<%= link_to "Contactar", new_conversation_path %>
但是我可以直接把这个 link 收件人放进去吗?
如果是,我应该在 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 ?
是的!您可以直接在 link 中传递个人收件人 ID,如下所示
<%= link_to "Contactar", new_conversation_path(recipient_id: @your_recipient.id %>
并在 new 方法中使用 params[:recipient_id]
访问 收件人的 ID。
这是我最后写的:
在我的产品列表中
<%= link_to "Contact", new_conversation_path(recipient_id: service.user.id) %>
在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
所以现在在对话新页面上,url 显示:/conversations/new?recipient_id=
感谢@Pavan
我在市场上工作。 我有一个包含所有产品的页面。
我想在每个产品上创建一个 link,以允许用户向卖家发送消息,创建一个新的对话。
我正在考虑用它创建一个 link:
<%= link_to "Contactar", new_conversation_path %>
但是我可以直接把这个 link 收件人放进去吗?
如果是,我应该在 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 ?
是的!您可以直接在 link 中传递个人收件人 ID,如下所示
<%= link_to "Contactar", new_conversation_path(recipient_id: @your_recipient.id %>
并在 new 方法中使用 params[:recipient_id]
访问 收件人的 ID。
这是我最后写的:
在我的产品列表中
<%= link_to "Contact", new_conversation_path(recipient_id: service.user.id) %>
在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
所以现在在对话新页面上,url 显示:/conversations/new?recipient_id=
感谢@Pavan