Skip to content

Instantly share code, notes, and snippets.

@randsina
Created August 10, 2016 14:40
Show Gist options
  • Save randsina/19ccd4e08a3a5829fe5264874657c53d to your computer and use it in GitHub Desktop.
Save randsina/19ccd4e08a3a5829fe5264874657c53d to your computer and use it in GitHub Desktop.
class AdminMessagesController < ApplicationController
before_action :authenticate_user!, only: [:create]
def create
@admin_message = current_user.admin_messages.new(message_params)
respond_to do |format|
if @admin_message.save
AdminMailer.new_message(email_params).deliver_later
@admin_message = AdminMessage.new
end
format.js { render :create }
end
end
private
def message_params
params.require(:admin_message).permit(
:sender_name,
:sender_phone,
:body
)
end
def email_params
message_params.merge({ recipient_email: Settings.instance.info_email, user_email: current_user.email })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment