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
# File 'app/controllers/contacts_controller.rb', line 16

def create
  @contact = Contact.new(contact_params)
  saved = @contact.save
  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
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)


35
36
37
# File 'app/controllers/contacts_controller.rb', line 35

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