summaryrefslogtreecommitdiff
path: root/app/controllers/gs_parameters_controller.rb
blob: 106ce765b2786fbf7656728952a82b42184322c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class GsParametersController < ApplicationController
  load_and_authorize_resource :gs_parameter

  before_filter :spread_breadcrumbs

  def index
    @gs_parameters = GsParameter.order([:entity, :section, :name])

    @entities = Hash.new()
    @gs_parameters.each do |parameter|
      if !@entities[parameter.entity] 
        @entities[parameter.entity] = Hash.new()
      end
      @entities[parameter.entity][parameter.section] = true
    end
  end

  def show
    @gs_parameter = GsParameter.find(params[:id])
  end

  def new
    @gs_parameter = GsParameter.new
  end

  def edit
    @gs_parameter = GsParameter.find(params[:id])
  end

  def update
    @gs_parameter = GsParameter.find(params[:id])
    if @gs_parameter.update_attributes(gs_parameter_params)
      redirect_to @gs_parameter, :notice  => t('gs_parameters.controller.successfuly_updated')
    else
      render :edit
    end
  end

  private
  def gs_parameter_params
    params.require(:gs_parameter).permit(:value, :class_type, :description)
  end

  def spread_breadcrumbs
    add_breadcrumb t("gs_parameters.index.page_title"), gs_parameters_path
    if @gs_parameter && !@gs_parameter.new_record?
      add_breadcrumb @gs_parameter, gs_parameter_path(@gs_parameter)
    end
  end
end