ruby-on-railsmailboxer

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 ?

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

Solution

  • But can i put in this link the recipient directly ?

    Yes! You can pass the individual recipient id directly in the link like below

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