Sha256: 4f31665a24fcdde48b05ab0bca05c8ae631ed401a83bec479d042ec8a6552043

Contents?: true

Size: 881 Bytes

Versions: 6

Compression:

Stored size: 881 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.respond_to?(:deliver_now) ? @contact_form.deliver_now : @contact_form.deliver
        flash.now[:notice] = 'Thank you for your message!'
        after_deliver
        render :new
      else
        flash.now[:error] = 'Sorry, this message was not sent successfully. '
        flash.now[:error] << @contact_form.errors.full_messages.map(&:to_s).join(",")
        render :new
      end
    rescue
      flash.now[:error] = 'Sorry, this message was not delivered.'
      render :new
    end

    def after_deliver
      return unless Sufia::Engine.config.enable_contact_form_delivery
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sufia-6.3.0 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-6.2.0 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-6.1.0 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-6.0.0 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-6.0.0.rc4 app/controllers/concerns/sufia/contact_form_controller_behavior.rb
sufia-6.0.0.rc3 app/controllers/concerns/sufia/contact_form_controller_behavior.rb