Class: Ecom::Core::UnitCostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ecom/core/unit_costs_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #logged_in?

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
# File 'app/controllers/ecom/core/unit_costs_controller.rb', line 12

def create
  unit_cost = UnitCost.new(unit_cost_params)
  if unit_cost.save
    render json: unit_cost, status: :created
  else
    render json: { success: false, errors: unit_cost.errors }, status: :unprocessable_entity
  end
end

#indexObject



6
7
8
9
10
# File 'app/controllers/ecom/core/unit_costs_controller.rb', line 6

def index
  unit_costs = UnitCost.where(active: true)
  serialized = ActiveModelSerializers::SerializableResource.new(unit_costs)
  render json: { success: true, data: serialized }
end