Module: Cats::Core::Common
- Extended by:
- ActiveSupport::Concern
- Included in:
- CashDonationsController, CommoditiesController, CommodityCategoriesController, CommodityDonationsController, CurrenciesController, DispatchAuthorizationsController, DispatchPlanItemsController, DispatchPlansController, DispatchTransactionsController, DispatchesController, InventoryAdjustmentsController, LoansController, LocationsController, LostCommoditiesController, PurchaseOrdersController, ReceiptAuthorizationsController, ReceiptTransactionsController, ReceiptsController, RolesController, RoundBeneficiariesController, RoundPlansController, RoutesController, StackTransactionsController, StacksController, StoresController, SwapsController, TransportersController, UnitConversionsController, UnitOfMeasuresController, UsersController
- Defined in:
- app/controllers/concerns/cats/core/common.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/concerns/cats/core/common.rb', line 24 def create obj = if block_given? yield else @clazz.new(model_params) end if obj.save render json: {success: true, data: serialize(obj)}, status: :created else render json: {success: false, error: obj.errors.[0]}, status: :unprocessable_entity end rescue StandardError => e render json: {success: false, error: e.} end |
#index ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/controllers/concerns/cats/core/common.rb', line 11 def index data = if block_given? yield else @clazz.all end render json: {success: true, data: serialize(data)} end |
#show ⇒ Object
20 21 22 |
# File 'app/controllers/concerns/cats/core/common.rb', line 20 def show render json: {success: true, data: serialize(@obj)} end |
#update ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/concerns/cats/core/common.rb', line 39 def update obj = if block_given? yield else obj = @obj end if obj.update(model_params) render json: {success: true, data: serialize(obj)} else render json: {success: false, error: obj.errors.[0]}, status: :unprocessable_entity end rescue StandardError => e render json: {success: false, error: e.} end |