Class: Beyond::TenantsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Beyond::TenantsController
- Defined in:
- app/controllers/beyond/tenants_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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..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 |
#edit ⇒ Object
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 |
#new ⇒ Object
3 4 5 |
# File 'app/controllers/beyond/tenants_controller.rb', line 3 def new @tenant = Tenant.new end |
#show ⇒ Object
22 23 24 |
# File 'app/controllers/beyond/tenants_controller.rb', line 22 def show @tenant = Tenant.find(params[:id]) end |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |
#update ⇒ Object
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 |