Class: Rails::Contact::ContactsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Rails::Contact::ContactsController
- Includes:
- Filterable
- Defined in:
- app/controllers/rails/contact/contacts_controller.rb
Constant Summary collapse
- METADATA_KEYS =
%w[ prefix middle_name suffix nickname company job_title department website birthday notes ].freeze
Instance Method Summary collapse
- #bulk_destroy ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #merge ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#bulk_destroy ⇒ Object
59 60 61 62 63 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 59 def bulk_destroy ids = params[:ids].to_s.split(",").map(&:to_i).reject(&:zero?).uniq Contact.where(id: ids).find_each(&:destroy!) redirect_to contacts_path, notice: "#{ids.size} contact(s) deleted." end |
#create ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 31 def create @contact = Contact.new(contact_params) assign_labels(@contact) if @contact.save enqueue_index(@contact.id) redirect_to contact_path(@contact), notice: "Contact created." else render "rails/contact/new", status: :unprocessable_entity end end |
#destroy ⇒ Object
52 53 54 55 56 57 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 52 def destroy id = @contact.id @contact.destroy! IndexContactJob.perform_later(id, remove: true) redirect_to contacts_path, notice: "Contact deleted." end |
#edit ⇒ Object
27 28 29 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 27 def edit render "rails/contact/edit" end |
#index ⇒ Object
11 12 13 14 15 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 11 def index @query = params[:q].to_s.strip @contacts = Search::Query.new(@query, filters: normalized_filters(filter_params)).call render "rails/contact/index" end |
#merge ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 65 def merge source_id = params[:source_id] target_id = params[:target_id] MergeContactsService.new(source_id: source_id, target_id: target_id).call redirect_to contact_path(target_id), notice: "Contacts merged." rescue StandardError => e redirect_to contacts_path, alert: "Merge failed: #{e.}" end |
#new ⇒ Object
21 22 23 24 25 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 21 def new @contact = Contact.new build_default_associations render "rails/contact/new" end |
#show ⇒ Object
17 18 19 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 17 def show render "rails/contact/show" end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/rails/contact/contacts_controller.rb', line 42 def update assign_labels(@contact) if @contact.update(contact_params) enqueue_index(@contact.id) redirect_to contact_path(@contact), notice: "Contact updated." else render "rails/contact/edit", status: :unprocessable_entity end end |