Class: Elabs::Admin::AdminContentApplicationController

Inherits:
AdminApplicationController show all
Defined in:
app/controllers/elabs/admin/admin_content_application_controller.rb

Constant Summary collapse

MODEL =
nil
SINGULAR_NAME =
nil
PLURAL_NAME =
nil

Constants inherited from AdminApplicationController

Elabs::Admin::AdminApplicationController::DEFAULT_ORDER_FIELD, Elabs::Admin::AdminApplicationController::MAX_ITEMS_PER_PAGE

Instance Method Summary collapse

Instance Method Details

#destroyObject

DELETE /<entity>/1 DELETE /<entity>/1.json



20
21
22
23
24
25
26
27
# File 'app/controllers/elabs/admin/admin_content_application_controller.rb', line 20

def destroy
  @entity.changed_by = current_user
  @entity.destroy
  respond_to do |format|
    format.html { redirect_to index_url, notice: format(_('%<model_name>s was successfully destroyed.'), model_name: self.class::SINGULAR_NAME.capitalize) }
    format.json { head :no_content }
  end
end

#indexObject

GET /<entity> GET /<entity>.json



12
13
14
15
16
# File 'app/controllers/elabs/admin/admin_content_application_controller.rb', line 12

def index
  order     = params['order_by'] || self.class::DEFAULT_ORDER_FIELD
  direction = params['direction'] || 'desc'
  create_instance_variable self.class::PLURAL_NAME, self.class::MODEL.order(order => direction).page(params[:page]).per(self.class::MAX_ITEMS_PER_PAGE)
end

#toggle_lockObject

rubocop:disable Metrics/AbcSize PUT /<entity>/1/toggle_lock



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/elabs/admin/admin_content_application_controller.rb', line 31

def toggle_lock
  @entity.changed_by = current_user
  respond_to do |format|
    if @entity.toggle(:locked).save
      format.html { redirect_to index_url, notice: lock_message(@entity) }
      format.json { render partial_name, status: :ok, locals: { "#{self.class::SINGULAR_NAME}": @entity } }
    else
      format.html { redirect_to index_url, error: 'An error prevented to update this entity' }
      format.json { render json: @entity.errors, status: :unprocessable_entity }
    end
  end
end