Sha256: 9badb0e6a2c2696ad90d408dfbf749484d14cc039b90695081a3d905448d5e39
Contents?: true
Size: 963 Bytes
Versions: 12
Compression:
Stored size: 963 Bytes
Contents
# frozen_string_literal: true module Alchemy class Api::AttachmentsController < Api::BaseController def index authorize! :index, Attachment @attachments = Attachment.all @attachments = @attachments.ransack(params[:q]).result if params[:page] @attachments = @attachments.page(params[:page]).per(params[:per_page]) end render json: @attachments, adapter: :json, root: "data", meta: meta_data end private def meta_data { total_count: total_count_value, per_page: per_page_value, page: page_value } end def total_count_value params[:page] ? @attachments.total_count : @attachments.size end def per_page_value if params[:page] (params[:per_page] || Kaminari.config.default_per_page).to_i else @attachments.size end end def page_value params[:page] ? params[:page].to_i : 1 end end end
Version data entries
12 entries across 12 versions & 1 rubygems