Class: RailsServerMonitor::ServersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_server_monitor/servers_controller.rb

Instance Method Summary collapse

Instance Method Details

#current_serverObject



23
24
25
# File 'app/controllers/rails_server_monitor/servers_controller.rb', line 23

def current_server
  @current_server ||= RailsServerMonitor::Server.find_by(id: params[:id])
end

#require_current_serverObject



27
28
29
# File 'app/controllers/rails_server_monitor/servers_controller.rb', line 27

def require_current_server
  redirect_to root_path, notice: "Server not found" if current_server.blank?
end

#showObject



7
8
9
10
11
12
# File 'app/controllers/rails_server_monitor/servers_controller.rb', line 7

def show
  @server = current_server
  @chart = RailsServerMonitor::ChartForServer.new(@server, timeline: params[:timeline])

  @title = @server.display_name
end

#updateObject



14
15
16
17
18
19
20
21
# File 'app/controllers/rails_server_monitor/servers_controller.rb', line 14

def update
  update_params = params.require(:server).permit(:custom_name, :custom_description)
  current_server.update!(update_params)
  redirect_to server_path(current_server)

rescue ActiveRecord::RecordInvalid => e
  render json: { error: e.message }, status: 422
end