Class: Madmin::ResourceController

Inherits:
ApplicationController show all
Includes:
SortHelper
Defined in:
app/controllers/madmin/resource_controller.rb

Instance Method Summary collapse

Methods included from SortHelper

#asc_icon, #default_sort_column, #default_sort_direction, #desc_icon, #sort_column, #sort_direction, #sortable

Methods inherited from ApplicationController

#authenticate_admin_user

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
# File 'app/controllers/madmin/resource_controller.rb', line 31

def create
  @record = resource.model.new(resource_params)
  if @record.save
    redirect_to resource.show_path(@record)
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



51
52
53
54
# File 'app/controllers/madmin/resource_controller.rb', line 51

def destroy
  @record.destroy
  redirect_to resource.index_path
end

#editObject



40
41
# File 'app/controllers/madmin/resource_controller.rb', line 40

def edit
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/madmin/resource_controller.rb', line 10

def index
  @pagy, @records = pagy(scoped_resources)

  respond_to do |format|
    format.html
    format.json {
      render json: @records.map { |r| {name: @resource.display_name(r), id: r.id} }
    }
  end
rescue Pagy::OverflowError
  params[:page] = 1
  retry
end

#newObject



27
28
29
# File 'app/controllers/madmin/resource_controller.rb', line 27

def new
  @record = resource.model.new
end

#showObject



24
25
# File 'app/controllers/madmin/resource_controller.rb', line 24

def show
end

#updateObject



43
44
45
46
47
48
49
# File 'app/controllers/madmin/resource_controller.rb', line 43

def update
  if @record.update(resource_params)
    redirect_to resource.show_path(@record)
  else
    render :edit, status: :unprocessable_entity
  end
end