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



28
29
30
31
32
33
34
35
# File 'app/controllers/madmin/resource_controller.rb', line 28

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



48
49
50
51
# File 'app/controllers/madmin/resource_controller.rb', line 48

def destroy
  @record.destroy
  redirect_to resource.index_path
end

#editObject



37
38
# File 'app/controllers/madmin/resource_controller.rb', line 37

def edit
end

#indexObject



10
11
12
13
14
15
16
17
18
19
# 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
end

#newObject



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

def new
  @record = resource.model.new(new_resource_params)
end

#showObject



21
22
# File 'app/controllers/madmin/resource_controller.rb', line 21

def show
end

#updateObject



40
41
42
43
44
45
46
# File 'app/controllers/madmin/resource_controller.rb', line 40

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