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
40
41
42
43
44
45
|
# File 'app/controllers/comee/core/application_controller.rb', line 40
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
54
55
56
|
# File 'app/controllers/comee/core/application_controller.rb', line 54
def authenticate
render json: {error: "Unauthorized"}, status: 401 if current_user.nil?
end
|
#current_application ⇒ Object
47
48
49
50
51
52
|
# File 'app/controllers/comee/core/application_controller.rb', line 47
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
|
# File 'app/controllers/comee/core/application_controller.rb', line 33
def current_user
return if token.nil?
user = User.find(auth["id"])
@current_user ||= user
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
59
60
61
62
63
64
65
|
# File 'app/controllers/comee/core/application_controller.rb', line 59
def skip_bullet
previous_value = Bullet.enable?
Bullet.enable = false
yield
ensure
Bullet.enable = previous_value
end
|