Class: Beyond::TenantsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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



28
29
30
31
# File 'app/controllers/beyond/tenants_controller.rb', line 28

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

#newObject



5
6
7
# File 'app/controllers/beyond/tenants_controller.rb', line 5

def new
  @tenant = Tenant.new
end

#showObject



24
25
26
# File 'app/controllers/beyond/tenants_controller.rb', line 24

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

#startObject



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

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



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

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



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

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