Sha256: 65e627960847c6527695ac7ebc637a7f3b05374f60042c4a5e0f56778d2c317f

Contents?: true

Size: 1.34 KB

Versions: 10

Compression:

Stored size: 1.34 KB

Contents

module Hyrax
  module ContactFormControllerBehavior
    extend ActiveSupport::Concern
    included do
      before_action :build_contact_form
      layout 'homepage'
    end

    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 => 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

    protected

      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

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.1.0 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.5 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.4 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.3 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.2 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.1 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.0.rc2 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
hyrax-1.0.0.rc1 app/controllers/concerns/hyrax/contact_form_controller_behavior.rb
test_hyrax-0.0.1.alpha app/controllers/concerns/hyrax/contact_form_controller_behavior.rb