Sha256: da113b5e71db0056c354443c34833b2bbb575e3b4b26facc0737f5cfe6d77a8d

Contents?: true

Size: 1013 Bytes

Versions: 5

Compression:

Stored size: 1013 Bytes

Contents

module Sufia
  module ContactFormControllerBehavior
    def new
      @contact_form = ContactForm.new
    end

    def create
      @contact_form = ContactForm.new(params[:contact_form])
      @contact_form.request = request
      # not spam and a valid form
      if @contact_form.deliver
        flash.now[:notice] = 'Thank you for your message!'
        after_deliver
        @contact_form = ContactForm.new
      else
        flash.now[:error] = 'Sorry, this message was not sent successfully. '
        flash.now[:error] << @contact_form.errors.full_messages.map(&:to_s).join(",")
      end
      render :new
    rescue RuntimeError => e
      logger.error("Contact form failed to send: #{e.inspect}")
      flash.now[:error] = 'Sorry, this message was not delivered.'
      render :new
    end

    # Override this method if you want to perform additional operations
    # when a email is successfully sent, such as sending a confirmation
    # response to the user.
    def after_deliver
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sufia-7.1.0 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-7.0.0 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-7.0.0.rc2 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-7.0.0.rc1 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-7.0.0.beta4 app/controllers/concerns/sufia/contact_form_controller_behavior.rb