module Users class OrdersController < Users::ApplicationController respond_to :json # /nested resource def index render json: {}, status: :not_found and return unless params[:list_id].present? @list = List.find(params[:list_id]) render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id) orders = @list.orders.include_relation(:product_orders) render json: orders, include: %w[list user product_orders product_orders.order] end end end