app/controllers/manage/configs_controller.rb in hackathon_manager-0.13.12 vs app/controllers/manage/configs_controller.rb in hackathon_manager-0.14.0
- old
+ new
@@ -1,15 +1,43 @@
class Manage::ConfigsController < Manage::ApplicationController
before_action :limit_access_admin
+ before_action :get_config, only: [:edit, :update]
respond_to :html, :json
- def show
- respond_with(Rails.configuration.hackathon)
+ def index
+ @config = HackathonConfig.get_all
+ respond_with(HackathonConfig.get_all)
end
+ def edit
+ end
+
+ def update
+ key = @config.var.to_sym
+ value = params[:hackathon_config][key]
+ value = true if value == 'true'
+ value = false if value == 'false'
+ if @config.value != value
+ @config.value = value
+ @config.save
+ redirect_to manage_configs_path, notice: "Config \"#{key}\" has been updated."
+ else
+ redirect_to manage_configs_path, notice: "Config \"#{key}\" was not changed"
+ end
+ end
+
private
+ def get_config
+ var = params[:id]
+ @config = HackathonConfig.find_by(var: var)
+ if @config.blank?
+ @config = HackathonConfig.new(var: var)
+ @config.value = HackathonConfig[var]
+ end
+ end
+
def limit_access_admin
- redirect_to manage_root_path unless current_user.admin?
+ redirect_to root_path unless current_user.admin?
end
end