services_controller.rb 1000 Bytes
Newer Older
1
class Admin::ServicesController < Admin::ApplicationController
2
3
  include ServiceParams

4
  before_action :service, only: [:edit, :update]
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

  def index
    @services = services_templates
  end

  def edit
    unless service.present?
      redirect_to admin_application_settings_services_path,
        alert: "Service is unknown or it doesn't exist"
    end
  end

  def update
    if service.update_attributes(application_services_params[:service])
      redirect_to admin_application_settings_services_path,
        notice: 'Application settings saved successfully'
    else
      render :edit
    end
  end

  private

  def services_templates
    templates = []

Marin Jankovski's avatar
Marin Jankovski committed
31
32
    Service.available_services_names.each do |service_name|
      service_template = service_name.concat("_service").camelize.constantize
33
34
35
36
37
38
39
40
41
42
      templates << service_template.where(template: true).first_or_create
    end

    templates
  end

  def service
    @service ||= Service.where(id: params[:id], template: true).first
  end
end