Sha256: 3bd5593944bcc632f3e05bfc768bb2da140378df776b81c7e8b2ba214b366c54

Contents?: true

Size: 1.4 KB

Versions: 48

Compression:

Stored size: 1.4 KB

Contents

module Hyrax
  class ContactFormController < ApplicationController
    before_action :build_contact_form
    layout 'homepage'

    def new; end

    def create
      # not spam and a valid form
      if @contact_form.valid?
        ContactMailer.contact(@contact_form).deliver_now
        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 => exception
      handle_create_exception(exception)
    end

    def handle_create_exception(exception)
      logger.error("Contact form failed to send: #{exception.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

    private

      def build_contact_form
        @contact_form = Hyrax::ContactForm.new(contact_form_params)
      end

      def contact_form_params
        return {} unless params.key?(:contact_form)
        params.require(:contact_form).permit(:contact_method, :category, :name, :email, :subject, :message)
      end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.9.5 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.9.4 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.9.3 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.9.2 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.9.1 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.9.0 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.8.0 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.7.2 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.7.1 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.7.0 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.6.0 app/controllers/hyrax/contact_form_controller.rb
hyrax-3.0.0.pre.rc1 app/controllers/hyrax/contact_form_controller.rb
hyrax-3.0.0.pre.beta3 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.5.1 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.5.0 app/controllers/hyrax/contact_form_controller.rb
hyrax-3.0.0.pre.beta2 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.4.1 app/controllers/hyrax/contact_form_controller.rb
hyrax-3.0.0.pre.beta1 app/controllers/hyrax/contact_form_controller.rb
hyrax-2.4.0 app/controllers/hyrax/contact_form_controller.rb