Sha256: ec1e18750f3c10b38cdc01e3eda7d664f05ce9b56622aa85c0f9c5c4999b685f
Contents?: true
Size: 1007 Bytes
Versions: 3
Compression:
Stored size: 1007 Bytes
Contents
class OrdersController < ApiController jsonapi_deserialize :order SORT_OPTIONS = { customer_name: "lower(customer_name)", date: "date", }.freeze def index orders = Order.all # order(jsonapi.sort_sql(SORT_OPTIONS, :name, :asc)). # paginate(jsonapi.will_paginate_options) render jsonapi_resources: orders, serializer: OrderSerializer, include: jsonapi.include_params end def show order = Order.find(params[:id]) render jsonapi_resource: order, serializer: OrderSerializer end def create order = Order.create!(order_params) render jsonapi_resource: order, serializer: OrderSerializer, status: :created end def update order = Order.find(params[:id]).update!(order_params) render jsonapi_resource: order, serializer: OrderSerializer, status: :ok end def destroy Order.find(params[:id]).destroy head :no_content end private def order_params params.require(:order).permit(:customer_name, :date) end end
Version data entries
3 entries across 3 versions & 1 rubygems