Class: ContactsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/contacts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/contacts_controller.rb', line 16

def create
  @contact = Contact.new(contact_params)
  # the website form field is invisible to human visitors and works as
  # a honeypot to spam robots
  saved = @contact.save unless @contact.website.present?
  # disabling this and replacing it with a daily digest
  # this is to mitigate the pain associated with contact spams
  # sent_email = send_message_to_admin(@contact)
  # if saved && sent_email == 'success'
  #   redirect_to root_path, notice: t("contacts.create.notice")
  # elsif saved && sent_email == 'exception'
  #   flash[:error] = t("contacts.create.warning")
  #   redirect_to :back
  # elsif saved && sent_email == 'invalid'
  #   flash[:error] =  "#{t("contacts.create.warning")} #{t('contacts.create.invalid_email')}"
  #   redirect_to :back
  # else
  #   flash[:error] = t('contacts.create.did_not_reach')
  #   redirect_to :back
  # end

  if saved || @contact.website.present?
    redirect_to root_path, notice: t("contacts.create.notice")
  else
    redirect_to :back, alert: t('contacts.create.did_not_reach')
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/contacts_controller.rb', line 6

def index
  @contacts = Contact.by_recent.paginate(:page => params[:page], :per_page => 35)
  switch_to_admin_layout
end

#showObject



11
12
13
14
# File 'app/controllers/contacts_controller.rb', line 11

def show
  @contact = Contact.find(params[:id])
  switch_to_admin_layout
end

#valid_email?(string) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/controllers/contacts_controller.rb', line 44

def valid_email?(string)
  (!string.blank? && string =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) ? true : false
end