class ContactController < ApplicationController

  # Intialize new object for user.
  def new
    @user = User.new
  end

  # Create new contact and send email
  def create
    @user = User.new
    @email = params[:email]
    @message = params[:message]
    @errors = { }

    if @message.nil? || @message.empty?
      @errors[:message] = "Message is mandatory"
    end

    if @errors.empty?
      ContactMailer.delay(queue: :mailer).new_contact(@email, @message)
      redirect_to(contact_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
  end

end
