Class: Integral::Backend::BaseController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Pundit
Defined in:
app/controllers/integral/backend/base_controller.rb

Overview

Base controller for backend inherited by all Integral backend controllers

Instance Method Summary collapse

Instance Method Details

#activitiesObject

GET /:id/activities



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/controllers/integral/backend/base_controller.rb', line 131

def activities
  authorize Version

  add_breadcrumb I18n.t('integral.actions.view'), backend_resource_url(@resource)
  add_breadcrumb I18n.t('integral.navigation.activity')

  @grid = Integral::Grids::ActivitiesGrid.new(activity_grid_options.except('page')) do |scope|
    scope.page(activity_grid_options['page']).per_page(25)
  end

  respond_to do |format|
    format.html { render template: 'integral/backend/activities/shared/index', locals: { form_url: activities_backend_resource_url(@resource) } }
    format.json { render json: { content: render_to_string(partial: 'integral/backend/activities/shared/grid', locals: { grid: @grid }) } }
  end
end

#activityObject

GET /:id/activities/:id



148
149
150
151
152
153
154
155
156
157
# File 'app/controllers/integral/backend/base_controller.rb', line 148

def activity
  authorize Version

  add_breadcrumb I18n.t('integral.navigation.activity'), activities_backend_resource_url(@resource)
  add_breadcrumb I18n.t('integral.actions.view')

  @activity = resource_version_klass.find(params[:activity_id]).decorate

  render template: 'integral/backend/activities/shared/show', locals: { record: @resource.decorate }
end

#createObject

POST / Resource creation



66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/integral/backend/base_controller.rb', line 66

def create
  add_breadcrumb I18n.t('integral.navigation.create')
  @resource = resource_klass.new(resource_params)

  yield if block_given?

  if @resource.save
    respond_successfully(notification_message('creation_success'), edit_backend_resource_url(@resource))
  else
    respond_failure(notification_message('creation_failure'), :new)
  end
end

#destroyObject

DELETE /:id



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/integral/backend/base_controller.rb', line 97

def destroy
  if @resource.destroy
    respond_to do |format|
      format.html { respond_successfully(notification_message('delete_success'), send("backend_#{controller_name}_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_#{controller_name}_path")
      end
      format.js { head :unprocessable_entity }
    end
  end
end

#duplicate {|cloned_resource| ... } ⇒ Object

POST /:id/duplicate Duplicate a resource

Yields:

  • (cloned_resource)


118
119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/integral/backend/base_controller.rb', line 118

def duplicate
  cloned_resource = @resource.dup

  yield cloned_resource if block_given?

  if cloned_resource.save
    respond_successfully(notification_message('clone_success'), send("edit_backend_#{controller_name.singularize}_path", cloned_resource.id))
  else
    respond_failure(notification_message('clone_failure'), :edit)
  end
end

#editObject

GET /:id/edit Resource edit screen



81
82
83
84
# File 'app/controllers/integral/backend/base_controller.rb', line 81

def edit
  add_breadcrumb I18n.t('integral.actions.view'), backend_resource_url(@resource)
  add_breadcrumb I18n.t('integral.actions.edit')
end

#indexObject

GET / Resource dashboard



38
# File 'app/controllers/integral/backend/base_controller.rb', line 38

def index; end

#listObject

GET /list Lists all resources



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

def list
  add_breadcrumb I18n.t('integral.navigation.list'), list_backend_resources_url

  respond_to do |format|
    format.html
    format.json do
      if params[:gridview].present?
        render json: { content: render_to_string(partial: "integral/backend/shared/grid/grid") }
      else
        respond_to_resource_selector
      end
    end
  end
end

#newObject

GET /new Resource creation screen



59
60
61
62
# File 'app/controllers/integral/backend/base_controller.rb', line 59

def new
  add_breadcrumb I18n.t('integral.navigation.new'), "new_backend_#{controller_name.singularize}_path".to_sym
  @resource = resource_klass.new
end

#showObject

GET /:id Show resource



31
32
33
34
# File 'app/controllers/integral/backend/base_controller.rb', line 31

def show
  add_breadcrumb I18n.t('integral.navigation.list'), list_backend_resources_url
  add_breadcrumb I18n.t('integral.actions.view')
end

#updateObject

PUT /:id Updating a resource



88
89
90
91
92
93
94
# File 'app/controllers/integral/backend/base_controller.rb', line 88

def update
  if @resource.update(resource_params)
    respond_successfully(notification_message('edit_success'), send("edit_backend_#{controller_name.singularize}_path", @resource.id))
  else
    respond_failure(notification_message('edit_failure'), :edit)
  end
end