45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
class ConfigurationFilesController < ApplicationController
|
|
before_filter :selected_server, only: [:new]
|
|
skip_before_action :verify_authenticity_token, only: [:update_by_api]
|
|
|
|
active_scaffold :"configuration_file" do |conf|
|
|
conf.columns[:file_type].form_ui = :select
|
|
end
|
|
|
|
def selected_server
|
|
@server = Server.find(params[:server_id])
|
|
@templates = ConfigurationTemplate.order(:name).all
|
|
end
|
|
|
|
def create_from_template
|
|
template = ConfigurationTemplate.find(params[:template_id].to_i)
|
|
file = ConfigurationFile.create_from_template!(template, params[:server_id].to_i)
|
|
redirect_to edit_configuration_file_path(file)
|
|
end
|
|
|
|
def update_by_form
|
|
file = ConfigurationFile.find(params[:id].to_i)
|
|
file.update_by_form(params[:content], params[:file_path])
|
|
redirect_to edit_configuration_file_path(file)
|
|
end
|
|
|
|
def update_by_api
|
|
file = ConfigurationFile.find(params[:id].to_i)
|
|
uploaded_file = params[:content]
|
|
file.update_by_api(uploaded_file)
|
|
render text: "OK"
|
|
end
|
|
|
|
def content
|
|
file = ConfigurationFile.find(params[:id].to_i)
|
|
render text: file.last_version.content
|
|
end
|
|
|
|
def destroy
|
|
file = ConfigurationFile.find(params[:id])
|
|
server = file.server
|
|
file.destroy!
|
|
redirect_to server_path(server)
|
|
end
|
|
end
|