class ConfigOptionsController < ApplicationController before_action :set_server_template def create @config_option = @server_template.config_options.build(config_option_params) if @config_option.save Activity.log(current_user, "added_config", "ServerTemplate", @server_template.id, { key: @config_option.config_key }) redirect_to @server_template, notice: "Config option added!" else redirect_to @server_template, alert: "Failed to add config option" end end def destroy @config_option = ConfigOption.find(params[:id]) authorize_user! @config_option.destroy Activity.log(current_user, "removed_config", "ServerTemplate", @server_template.id, { key: @config_option.config_key }) redirect_to @server_template, notice: "Config option deleted!" end private def set_server_template @server_template = current_user.server_templates.find(params[:server_template_id]) end def config_option_params params.require(:config_option).permit(:config_key, :config_value) end def authorize_user! redirect_to dashboard_path, alert: "Not authorized" unless @server_template.user_id == current_user.id end end