Class: WcoHosting::ServerhostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wco_hosting/serverhosts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 4

def create
  @serverhost = WcoHosting::Serverhost.new params[:serverhost].permit!
  authorize! :create, @serverhost

  @serverhost.do_create_server! unless params[:skip_do_resource]

  flag = @serverhost.save
  if flag
    flash[:notice] = 'Success.'
    redirect_to action: :index
  else
    flash[:alert] = "Cannot create serverhost: #{@serverhost.errors.full_messages.join(', ')}."
    render action: :index
  end
end

#destroyObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 20

def destroy
  @serverhost = WcoHosting::Serverhost.find params[:id]
  authorize! :destroy, @serverhost
  out = HTTParty.delete( "https://api.digitalocean.com/v2/droplets/#{@serverhost.do_id}",
    headers: { 'Authorization' => "Bearer #{DO_READER_TOKEN}" },
      :debug_output => $stdout,
    );
  puts! out, 'out'
  flag = @serverhost.destroy!
  if flag
    flash_notice @serverhost
  else
    flash_alert @serverhost
  end
  redirect_to action: :index
end

#editObject



37
38
39
40
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 37

def edit
  @serverhost = WcoHosting::Serverhost.find params[:id]
  authorize! :edit, @serverhost
end

#indexObject



42
43
44
45
46
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 42

def index
  authorize! :index, WcoHosting::Serverhost
  @serverhosts = WcoHosting::Serverhost.all.order_by name: :asc
  @new_serverhost = WcoHosting::Serverhost.new
end

#newObject



48
49
50
51
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 48

def new
  authorize! :index, WcoHosting::Serverhost
  @new_serverhost = WcoHosting::Serverhost.new
end

#showObject



53
54
55
56
57
58
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 53

def show
  @serverhost = WcoHosting::Serverhost.find params[:id]
  authorize! :show, @serverhost

  @files = @serverhost.files
end

#updateObject



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/wco_hosting/serverhosts_controller.rb', line 60

def update
  @serverhost = WcoHosting::Serverhost.find params[:id]
  authorize! :update, @serverhost
  if @serverhost.update_attributes( params[:serverhost].permit! )
    flash_notice @serverhost
  else
    flash_alert @serverhost
  end
  redirect_to action: :index
end