Class: Integral::Backend::BaseController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Integral::Backend::BaseController
- Includes:
- Pundit
- Defined in:
- app/controllers/integral/backend/base_controller.rb
Overview
Base controller for backend inherited by all Integral backend controllers
Direct Known Subclasses
ActivitiesController, CategoriesController, ImagesController, ListsController, PagesController, PostsController, SettingsController, StaticPagesController, UsersController
Instance Method Summary collapse
-
#activities ⇒ Object
GET /:id/activities.
-
#activity ⇒ Object
GET /:id/activities/:id.
-
#create ⇒ Object
POST / Resource creation.
-
#destroy ⇒ Object
DELETE /:id.
-
#duplicate {|cloned_resource| ... } ⇒ Object
POST /:id/duplicate Duplicate a resource.
-
#edit ⇒ Object
GET /:id/edit Resource edit screen.
-
#index ⇒ Object
GET / Lists all resources.
-
#list ⇒ Object
GET /list Lists all resources.
-
#new ⇒ Object
GET /new Resource creation screen.
-
#show ⇒ Object
GET /:id Show resource.
-
#update ⇒ Object
PUT /:id Updating a resource.
Instance Method Details
#activities ⇒ Object
GET /:id/activities
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/controllers/integral/backend/base_controller.rb', line 153 def activities Version I18n.t('integral.navigation.edit'), "edit_backend_#{controller_name.singularize}_path".to_sym I18n.t('integral.navigation.activity') @grid = Integral::Grids::ActivitiesGrid.new(.except('page')) do |scope| scope.page(['page']).per_page(25) end respond_to do |format| format.html { render template: 'integral/backend/activities/shared/index', locals: { form_url: send("activities_backend_#{controller_name.singularize}_url", @resource.id) } } format.json { render json: { content: render_to_string(partial: 'integral/backend/activities/shared/grid', locals: { grid: @grid }) } } end end |
#activity ⇒ Object
GET /:id/activities/:id
170 171 172 173 174 175 176 177 178 179 |
# File 'app/controllers/integral/backend/base_controller.rb', line 170 def activity Version I18n.t('integral.navigation.activity'), "activities_backend_#{controller_name.singularize}_url".to_sym 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 |
#create ⇒ Object
POST / Resource creation
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/integral/backend/base_controller.rb', line 87 def create I18n.t('integral.navigation.create'), "new_backend_#{controller_name.singularize}_path".to_sym @resource = resource_klass.new(resource_params) yield if block_given? if @resource.save respond_successfully(('creation_success'), send("edit_backend_#{controller_name.singularize}_path", @resource.id)) else respond_failure(('creation_failure'), :new) end end |
#destroy ⇒ Object
DELETE /:id
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/controllers/integral/backend/base_controller.rb', line 118 def destroy if @resource.destroy respond_to do |format| format.html { respond_successfully(('delete_success'), send("backend_#{controller_name}_path")) } format.js { head :no_content } end else respond_to do |format| format.html do = @resource.errors..to_sentence flash[:error] = "#{('delete_failure')} - #{}" 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
140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/integral/backend/base_controller.rb', line 140 def duplicate cloned_resource = @resource.dup yield cloned_resource if block_given? if cloned_resource.save respond_successfully(('clone_success'), send("edit_backend_#{controller_name.singularize}_path", cloned_resource.id)) else respond_failure(('clone_failure'), :edit) end end |
#edit ⇒ Object
GET /:id/edit Resource edit screen
102 103 104 105 |
# File 'app/controllers/integral/backend/base_controller.rb', line 102 def edit I18n.t('integral.actions.view'), "backend_#{controller_name.singularize}_path".to_sym I18n.t('integral.navigation.edit'), "edit_backend_#{controller_name.singularize}_path".to_sym end |
#index ⇒ Object
GET / Lists all resources
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/integral/backend/base_controller.rb', line 38 def index # TODO: This default behaviour will switch to 'list' action respond_to do |format| format.html do set_grid end format.json do if params[:gridview].present? set_grid render json: { content: render_to_string(partial: "integral/backend/#{controller_name}/grid", locals: { grid: @grid }) } else respond_to_record_selector end end end end |
#list ⇒ Object
GET /list Lists all resources
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/integral/backend/base_controller.rb', line 59 def list I18n.t('integral.navigation.list'), "new_backend_#{controller_name.singularize}_path".to_sym respond_to do |format| format.html do set_grid end format.json do if params[:gridview].present? set_grid render json: { content: render_to_string(partial: "integral/backend/#{controller_name}/grid", locals: { grid: @grid }) } else respond_to_record_selector end end end end |
#new ⇒ Object
GET /new Resource creation screen
80 81 82 83 |
# File 'app/controllers/integral/backend/base_controller.rb', line 80 def new I18n.t('integral.navigation.new'), "new_backend_#{controller_name.singularize}_path".to_sym @resource = resource_klass.new end |
#show ⇒ Object
GET /:id Show resource
31 32 33 34 |
# File 'app/controllers/integral/backend/base_controller.rb', line 31 def show I18n.t('integral.navigation.list'), "list_backend_#{controller_name}_path".to_sym I18n.t('integral.actions.view'), "backend_#{controller_name.singularize}_path".to_sym end |
#update ⇒ Object
PUT /:id Updating a resource
109 110 111 112 113 114 115 |
# File 'app/controllers/integral/backend/base_controller.rb', line 109 def update if @resource.update(resource_params) respond_successfully(('edit_success'), send("edit_backend_#{controller_name.singularize}_path", @resource.id)) else respond_failure(('edit_failure'), :edit) end end |