Class: Rails::Contact::ContactsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails/contact/contacts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/rails/contact/contacts_controller.rb', line 20

def create
  @contact = Contact.new(contact_params)
  if @contact.save
    enqueue_index(@contact.id)
    redirect_to contact_path(@contact), notice: "Contact created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



39
40
41
42
43
44
# File 'app/controllers/rails/contact/contacts_controller.rb', line 39

def destroy
  id = @contact.id
  @contact.destroy!
  IndexContactJob.perform_later(id, remove: true)
  redirect_to contacts_path, notice: "Contact deleted."
end

#editObject



18
# File 'app/controllers/rails/contact/contacts_controller.rb', line 18

def edit; end

#indexObject



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

def index
  @query = params[:q].to_s.strip
  @contacts = Search::Query.new(@query, filters: filter_params).call
end

#newObject



13
14
15
16
# File 'app/controllers/rails/contact/contacts_controller.rb', line 13

def new
  @contact = Contact.new
  build_default_associations
end

#showObject



11
# File 'app/controllers/rails/contact/contacts_controller.rb', line 11

def show; end

#updateObject



30
31
32
33
34
35
36
37
# File 'app/controllers/rails/contact/contacts_controller.rb', line 30

def update
  if @contact.update(contact_params)
    enqueue_index(@contact.id)
    redirect_to contact_path(@contact), notice: "Contact updated."
  else
    render :edit, status: :unprocessable_entity
  end
end