Class: Integral::Backend::CategoriesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/integral/backend/categories_controller.rb

Overview

Categories controller

Instance Method Summary collapse

Methods inherited from BaseController

#activities, #activity, #duplicate, #index, #list, #new, #show

Instance Method Details

#createObject

POST / Category creation



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/integral/backend/categories_controller.rb', line 27

def create
  @resource = Integral::Category.new(resource_params)

  if @resource.save
    flash[:notice] = notification_message('creation_success')
    render json: { redirect_url: request.referrer }, status: :created
  else
    render json: { message: notification_message('creation_failure') }, status: :unprocessable_entity
  end
end

#destroyObject

Override redirect path DELETE /:id



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/integral/backend/categories_controller.rb', line 40

def destroy
  if @resource.destroy
    respond_to do |format|
      format.html { respond_successfully(notification_message('delete_success'), send("backend_posts_path")) }
      format.js { head :no_content }
    end
  else
    respond_to do |format|
      format.html do
        error_message = @resource.errors.full_messages.to_sentence
        flash[:error] = "#{notification_message('delete_failure')} - #{error_message}"

        redirect_to send("backend_posts_path")
      end
      format.js { head :unprocessable_entity }
    end
  end
end

#editObject

GET /:id/edit Category update screen



21
22
23
# File 'app/controllers/integral/backend/categories_controller.rb', line 21

def edit
  render json: { content: render_to_string(partial: 'integral/backend/categories/modal', locals: { category: @resource, title: 'Edit Category', modal_id: "modal--category-edit-#{@resource.id}" }) }
end

#updateObject

PUT /:id Updating a resource



10
11
12
13
14
15
16
17
# File 'app/controllers/integral/backend/categories_controller.rb', line 10

def update
  if @resource.update(resource_params)
    flash[:notice] = notification_message('edit_success')
    render json: { redirect_url: request.referrer }, status: :created
  else
    render json: { message: notification_message('edit_failure') }, status: :unprocessable_entity
  end
end