Sha256: 63f25bc11d519d465bb838b346d3c9c998c5fb322f8053671dad416dda6205e7

Contents?: true

Size: 1.56 KB

Versions: 33

Compression:

Stored size: 1.56 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_create_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

33 entries across 33 versions & 1 rubygems

Version Path
trusty-cms-1.2.29 app/controllers/admin/configuration_controller.rb
trusty-cms-1.2.28 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.28 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.27 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.26 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.25 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.24 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.23 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.22 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.21 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.20 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.19 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.18 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.17 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.16 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.15 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.14 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.13 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.12 app/controllers/admin/configuration_controller.rb
trusty-cms-1.1.11 app/controllers/admin/configuration_controller.rb