Class: Beyond::TenantsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/beyond/tenants_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/beyond/tenants_controller.rb', line 7

def create
  tenant = Tenant.new(create_params)
  tenant.user = current_user
  begin
    if tenant.save
      redirect_to root_url, notice: "You have successfully created #{tenant.name}"
    else
      errors = tenant.errors.messages.map { |k, v| k.to_s+' ' + v.join(' and ')+' ' }
      redirect_to root_url, alert: "There was an error while trying to create #{tenant.name}. " + errors.join(' ')
    end
  rescue
    redirect_to root_url, alert: "There was an error while trying to create #{tenant.name}. "
  end
end

#editObject



26
27
28
29
# File 'app/controllers/beyond/tenants_controller.rb', line 26

def edit
  @tenant = Tenant.find(params[:id])
  @configs = @tenant.configs.group_by { |_, v| v['category'] }
end

#newObject



3
4
5
# File 'app/controllers/beyond/tenants_controller.rb', line 3

def new
  @tenant = Tenant.new
end

#showObject



22
23
24
# File 'app/controllers/beyond/tenants_controller.rb', line 22

def show
  @tenant = Tenant.find(params[:id])
end

#startObject



44
45
46
47
48
49
50
51
# File 'app/controllers/beyond/tenants_controller.rb', line 44

def start
  begin
    Tenant.find(params[:id]).start
    redirect_to root_url, notice: 'Tenant started'
  rescue
    redirect_to root_url, alert: 'Error: couldn\'t start tenant'
  end
end

#stopObject



53
54
55
56
57
58
59
60
# File 'app/controllers/beyond/tenants_controller.rb', line 53

def stop
  begin
    Tenant.find(params[:id]).stop
    redirect_to root_url, notice: 'Tenant stoped'
  rescue
    redirect_to root_url, alert: 'Error: couldn\'t stop tenant'
  end
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/beyond/tenants_controller.rb', line 31

def update
  tenant = Tenant.find(params[:id])
  changes = params.select { |k, _| k =~ /^config_.+/ }
  changes = Hash[changes.map { |k, v| [k.to_s.sub(/^config_/, ''), v] }]
  begin
    tenant.update_configs changes
  rescue
    redirect_to root_url, alert: 'There was an error while trying to save your configurations to file.'
    return
  end
  redirect_to root_url, notice: 'You have successfully updated you configurations!'
end