I have used mailboxer gem for the messaging between users in my website.
Which is based on spree module.
I want to add the product id with the conversation so user can filter the conversations according to the products.
How can I achieve this?
Here is the code for message_controller file:
module Spree
module Admin
class MessagesController < Spree::BaseController
before_action :authenticate_spree_user!
def index
filtered_messages = Mailboxer::Message.ads_id(params[:ad_id])
end
def new
@chosen_recipient = Spree::User.find_by(id: params[:to].to_i) if params[:to]
end
def create
product_id = params[:product_id]
recipients = Spree::User.where(id: params['recipients'])
conversation = current_spree_user.send_message(recipients, params[:message][:body], params[:message][:subject], params[:product_id]).conversation
flash[:success] = 'Message has been sent!'
redirect_to '/admin/conversations'
end
private
def conversation_params
#params.require(:mailboxer_conversations).permit(:ad_id)
params.permit(:ad_id)
end
end
end
end