Class: Adminable::ResourcesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/adminable/resources_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#welcome

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/adminable/resources_controller.rb', line 24

def create
  @entry = @resource.model.new(resource_params)

  if @entry.save
    redirect_to polymorphic_path(@resource.model),
                notice: t(
                  'adminable.resources.created',
                  resource: @resource.model.model_name.human
                )
  else
    flash.now[:alert] = @entry.errors.full_messages
    render :new
  end
end

#destroyObject



52
53
54
55
56
57
58
59
60
# File 'app/controllers/adminable/resources_controller.rb', line 52

def destroy
  @entry.destroy

  redirect_to polymorphic_path(@resource.model),
              notice: t(
                'adminable.resources.deleted',
                resource: @resource.model.model_name.human
              )
end

#editObject



21
22
# File 'app/controllers/adminable/resources_controller.rb', line 21

def edit
end

#indexObject



11
12
13
14
15
# File 'app/controllers/adminable/resources_controller.rb', line 11

def index
  @q = @resource.model.ransack(params[:q])
  @entries = @q.result.includes(*@resource.includes).all
               .page(params[:page]).per(25)
end

#newObject



17
18
19
# File 'app/controllers/adminable/resources_controller.rb', line 17

def new
  @entry = @resource.model.new
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/adminable/resources_controller.rb', line 39

def update
  if @entry.update(resource_params)
    redirect_to polymorphic_path(@resource.model),
                notice: t(
                  'adminable.resources.updated',
                  resource: @resource.model.model_name.human
                )
  else
    flash.now[:alert] = @entry.errors.full_messages
    render :edit
  end
end