Skip to content

Instantly share code, notes, and snippets.

@joelbrewer
Last active January 4, 2016 20:09
Show Gist options
  • Save joelbrewer/8671822 to your computer and use it in GitHub Desktop.
Save joelbrewer/8671822 to your computer and use it in GitHub Desktop.
conversations_controller.rb
class ConversationsController < ApplicationController
before_filter :authenticate_user!
def create
conversation_params
recipient_email = params[:conversation][:recipients]
recipient = User.where(email: recipient_email)
current_user.send_message(recipient, params[:conversation][:body], params[:conversation][:subject]).conversation
end
def index
@inbox = current_user.mailbox.inbox
end
def show
@conversation = current_user.mailbox.conversations.find(params[:id])
end
def reply
@conversation = current_user.mailbox.conversations.find(params[:id])
current_user.reply_to_conversation(@conversation, *message_params)
redirect_to @conversation
end
private
def conversation_params
params.require(:conversation).permit(
:recipients,
:body,
:subject)
end
def message_params
params.require(:message).permit(
:body,
:subject)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment