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, #destroy, #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.now[: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

#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.now[: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