Module: Sufia::ContactFormControllerBehavior

Included in:
ContactFormController
Defined in:
app/controllers/concerns/sufia/contact_form_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#after_deliverObject

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.



29
30
# File 'app/controllers/concerns/sufia/contact_form_controller_behavior.rb', line 29

def after_deliver
end

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/concerns/sufia/contact_form_controller_behavior.rb', line 7

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

#newObject



3
4
5
# File 'app/controllers/concerns/sufia/contact_form_controller_behavior.rb', line 3

def new
  @contact_form = ContactForm.new
end