Class: Fae::BaseController

Inherits:
ApplicationController show all
Includes:
Cloneable
Defined in:
app/controllers/fae/base_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/fae/base_controller.rb', line 32

def create
  return create_from_existing(params[:from_existing]) if params[:from_existing].present?

  @item = @klass.new(item_params)

  if @item.save
    redirect_to @index_path, notice: t('fae.save_notice')
  else
    build_assets
    flash[:alert] = t('fae.save_error')
    render action: 'new'
  end
end

#destroyObject



56
57
58
59
60
61
62
# File 'app/controllers/fae/base_controller.rb', line 56

def destroy
  if @item.destroy
    redirect_to @index_path, notice: t('fae.delete_notice')
  else
    redirect_to @index_path, flash: { error: t('fae.delete_error') }
  end
end

#editObject



28
29
30
# File 'app/controllers/fae/base_controller.rb', line 28

def edit
  build_assets
end

#filterObject



64
65
66
67
68
69
70
71
72
# File 'app/controllers/fae/base_controller.rb', line 64

def filter
  if use_pagination
    @items = @klass.filter(params).fae_sort(params).page(params[:page])
  else
    @items = @klass.filter(params).fae_sort(params)
  end

  render :index, layout: false
end

#indexObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/fae/base_controller.rb', line 11

def index
  if use_pagination
    @items = @klass.for_fae_index.page(params[:page])
  else
    @items = @klass.for_fae_index
  end
  respond_to do |format|
    format.html
    format.csv { send_data @items.to_csv, filename: @items.name.parameterize + "." + Time.now.to_s(:filename) + '.csv'  }
  end
end

#newObject



23
24
25
26
# File 'app/controllers/fae/base_controller.rb', line 23

def new
  @item = @klass.new
  build_assets
end

#showObject



74
75
76
77
# File 'app/controllers/fae/base_controller.rb', line 74

def show
  # show action is hidden by default, override as needed
  show_404
end

#updateObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/fae/base_controller.rb', line 46

def update
  if @item.update(item_params)
    redirect_to @index_path, notice: t('fae.save_notice')
  else
    build_assets
    flash[:alert] = t('fae.save_error')
    render action: 'edit'
  end
end