Class: Fae::BaseController

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

Instance Method Summary collapse

Methods included from NavItems

#nav_items

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/fae/base_controller.rb', line 27

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



51
52
53
54
55
56
57
# File 'app/controllers/fae/base_controller.rb', line 51

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



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

def edit
  build_assets
end

#filterObject



59
60
61
62
63
64
65
66
67
# File 'app/controllers/fae/base_controller.rb', line 59

def filter
  if params[:commit] == "Reset Search"
    @items = @klass.filter_all
  else
    @items = @klass.filter(params[:filter])
  end

  render :index, layout: false
end

#indexObject



10
11
12
13
14
15
16
# File 'app/controllers/fae/base_controller.rb', line 10

def index
  @items = @klass.for_fae_index
  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



18
19
20
21
# File 'app/controllers/fae/base_controller.rb', line 18

def new
  @item = @klass.new
  build_assets
end

#updateObject



41
42
43
44
45
46
47
48
49
# File 'app/controllers/fae/base_controller.rb', line 41

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