Sha256: 7a5a79d50b5ec17a4d1798b27b89c7319d85845dba6877d55c0d786debce5bdd

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module GeorgiaMailer
  class MessagesController < ::ApplicationController

    # Convenient method to create and check for spam
    def create
      @message = GeorgiaMailer::Message.new(message_params)
      if @message.save
        SpamWorker.perform_async(@message.id)
        respond_to do |format|
          format.html { redirect_to :back, notice: 'Message delivered successfully' }
          format.js   { render layout: false }
        end
      else
        respond_to do |format|
          format.html { redirect_to :back, alert: 'Oups. Something went wrong.' }
          format.js   { render layout: false }
        end
      end
    end

    private

    def message_params
      @message_params = {}
      params[:message].each do |key, value|
        @message_params[key] = value.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
      end
      @message_params[:referrer] = request.referrer
      @message_params[:user_ip] = request.remote_ip
      @message_params[:user_agent] = request.user_agent
      @message_params
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
georgia_mailer-0.1.2 app/controllers/georgia_mailer/messages_controller.rb
georgia_mailer-0.1.1 app/controllers/georgia_mailer/messages_controller.rb
georgia_mailer-0.1.0 app/controllers/georgia_mailer/messages_controller.rb