Sha256: d8f86ea11c13c0a5ae51c4c77a175a1d8ef50df50b80891e8c9bbcd043d0b925

Contents?: true

Size: 1.57 KB

Versions: 30

Compression:

Stored size: 1.57 KB

Contents

class Admin::ConfigurationController < ApplicationController

  # Admin::ConfigurationController handles the batch-updating of TrustyCms::Config entries.
  # It accepts any set of config name-value pairs but is accessible only to administrators.
  # Note that configuration is routed as a singular resource so we only deal with show/edit/update
  # and the show and edit views determine what set of config values is shown and made editable.

  before_filter :initialize_config

  only_allow_access_to :edit, :update,
    :when => [:admin],
    :denied_url => { :controller => 'admin/configuration', :action => 'show' },
    :denied_message => 'You must have admin privileges to edit site configuration.'

  def show
    @user = current_user
    render
  end

  def edit
    render
  end

  def update
    if params[:trusty_config]
      begin
        TrustyCms.config.transaction do
          params[:trusty_config].each_pair do |key, value|
            @trusty_config[key] = TrustyCms::Config.find_or_initialize_by(key: key)
            @trusty_config[key].value = value      # validation sets errors on @trusty_config['key'] that the helper methods will pick up
          end
          redirect_to :action => :show
        end
      rescue ActiveRecord::RecordInvalid => e
        flash[:error] = "Configuration error: please check the form"
        render :action => :edit
      rescue TrustyCms::Config::ConfigError => e
        flash[:error] = "Configuration error: #{e}"
        render :action => :edit
      end
    end
  end

protected

  def initialize_config
    @trusty_config = {}
  end

end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
trusty-cms-2.0.28 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.27 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.26 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.25 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.24 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.23 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.22 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.21 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.21.alpha app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.20 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.2 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.19 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.18 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.17 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.16 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.15 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.14 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.13 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.12 app/controllers/admin/configuration_controller.rb
trusty-cms-2.0.11 app/controllers/admin/configuration_controller.rb