Class: Comee::Core::ApplicationController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- Comee::Core::ApplicationController
show all
- Includes:
- Pagination
- Defined in:
- app/controllers/comee/core/application_controller.rb
Direct Known Subclasses
AccessController, AdditionalServicesController, AgentsController, ApplicationModulesController, BackOrdersController, ClientAddressesController, ClientPricesController, ClientWarehousesController, ClientsController, ContactsController, CurrenciesController, CustomerOrderItemsController, CustomerOrdersController, CustomsDetailsController, ExternalRfqsController, FulfillmentCentersController, GoodsReceivedNotesController, ItemStatusesController, LookupsController, NotificationsController, ProductLookupsController, ProductsController, QuotationRequestItemsController, QuotationRequestsController, RolesController, SalesOrderItemsController, SalesOrdersController, ShipmentItemsController, StockTransferRequestItemsController, StockTransferRequestsController, StoreItemsController, StoresController, SupplierAddressesController, SuppliersController, UnitConversionsController, UnitsController, UserApplicationRolesController, UsersController
Instance Method Summary
collapse
Methods included from Pagination
#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #per_page
Instance Method Details
#application_code ⇒ Object
42
43
44
45
46
47
|
# File 'app/controllers/comee/core/application_controller.rb', line 42
def application_code
code = Rails.application.config.application_code
raise(StandardError, "Code is not set for the current application.") unless code
code
end
|
#authenticate ⇒ Object
56
57
58
|
# File 'app/controllers/comee/core/application_controller.rb', line 56
def authenticate
render json: {error: "Unauthorized"}, status: 401 if current_user.nil?
end
|
#current_application ⇒ Object
49
50
51
52
53
54
|
# File 'app/controllers/comee/core/application_controller.rb', line 49
def current_application
app_code = application_code
return ApplicationModule.find_by(code: app_code) if app_code
nil
end
|
#current_user ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'app/controllers/comee/core/application_controller.rb', line 33
def current_user
return if token.nil?
decoded = auth
return if decoded.nil?
@current_user ||= User.find_by(id: decoded["id"])
end
|
#render_content(data, options = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/comee/core/application_controller.rb', line 8
def render_content(data, options = {})
result = {success: true}
if params[:page]
total = data.count
data = data.then(&paginate)
result[:page] = params[:page].to_i
result[:total] = total
end
result[:data] = serialize(data, options)
render json: result
end
|
#render_error(error) ⇒ Object
29
30
31
|
# File 'app/controllers/comee/core/application_controller.rb', line 29
def render_error(error)
render json: {success: false, error: error.message}, status: 422
end
|
#skip_bullet ⇒ Object
In case we want to disable bullet for specific controller actions
61
62
63
64
65
66
67
|
# File 'app/controllers/comee/core/application_controller.rb', line 61
def skip_bullet
previous_value = Bullet.enable?
Bullet.enable = false
yield
ensure
Bullet.enable = previous_value
end
|