Class: Adminka::CrudController

Inherits:
AdminController show all
Includes:
Staff
Defined in:
app/controllers/adminka/crud_controller.rb

Instance Method Summary collapse

Methods included from Staff

#select_fields

Constructor Details

#initializeCrudController

Returns a new instance of CrudController.



7
8
9
10
11
# File 'app/controllers/adminka/crud_controller.rb', line 7

def initialize
  super
  @config = @menu[self.class::MODEL.downcase]
  @model = Object.const_get(self.class::MODEL)
end

Instance Method Details

#createObject



18
19
20
21
22
23
# File 'app/controllers/adminka/crud_controller.rb', line 18

def create
  @entity = @model.new(entity_params)
  return render :new unless @entity.save
  flash[:notice] = t('adminka.create')
  redirect_to @entity
end

#destroyObject



47
48
49
50
51
# File 'app/controllers/adminka/crud_controller.rb', line 47

def destroy
  @model.find(params[:id]).destroy
  flash[:notice] = t('adminka.delete')
  redirect_to adminka.send("#{@model.to_s.downcase.pluralize}_path")
end

#editObject



33
34
35
# File 'app/controllers/adminka/crud_controller.rb', line 33

def edit
  @entity = @model.select(select_fields('edit')).find(params[:id])
end

#indexObject



13
14
15
16
# File 'app/controllers/adminka/crud_controller.rb', line 13

def index
  @q = @model.ransack(params[:q])
  @entities = @q.result.select(select_fields('list')).page(params[:page])
end

#newObject



25
26
27
# File 'app/controllers/adminka/crud_controller.rb', line 25

def new
  @entity = @model.new
end

#showObject



29
30
31
# File 'app/controllers/adminka/crud_controller.rb', line 29

def show
  @entity = @model.select(select_fields('show')).find(params[:id])
end

#updateObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/adminka/crud_controller.rb', line 37

def update
  @entity = @model.find(params[:id])
  if @entity.update(entity_params)
    flash[:notice] = t('adminka.update')
    redirect_to @entity
  else
    render :edit
  end
end