36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
class StartupParamsController < ApplicationController
|
|
before_action :set_server_template
|
|
|
|
def create
|
|
@startup_param = @server_template.startup_params.build(startup_param_params)
|
|
|
|
if @startup_param.save
|
|
Activity.log(current_user, "added_param", "ServerTemplate", @server_template.id, { key: @startup_param.param_key })
|
|
redirect_to @server_template, notice: "Startup parameter added!"
|
|
else
|
|
redirect_to @server_template, alert: "Failed to add parameter"
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@startup_param = StartupParam.find(params[:id])
|
|
authorize_user!
|
|
@startup_param.destroy
|
|
Activity.log(current_user, "removed_param", "ServerTemplate", @server_template.id, { key: @startup_param.param_key })
|
|
redirect_to @server_template, notice: "Startup parameter deleted!"
|
|
end
|
|
|
|
private
|
|
|
|
def set_server_template
|
|
@server_template = current_user.server_templates.find(params[:server_template_id])
|
|
end
|
|
|
|
def startup_param_params
|
|
params.require(:startup_param).permit(:param_key, :param_value)
|
|
end
|
|
|
|
def authorize_user!
|
|
redirect_to dashboard_path, alert: "Not authorized" unless @server_template.user_id == current_user.id
|
|
end
|
|
end
|