scinote-web/app/serializers/api/v1/repository_asset_value_serializer.rb

30 lines
590 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module Api
module V1
class RepositoryAssetValueSerializer < ActiveModel::Serializer
attributes :file_id, :file_name, :file_size, :url
def file_id
object.asset&.id
end
def file_name
object.asset&.file_name
end
def file_size
object.asset&.file_size
end
def url
2019-07-26 21:58:51 +08:00
if !object.asset&.file&.attached?
nil
else
2019-07-26 21:58:51 +08:00
Rails.application.routes.url_helpers.rails_blob_path(object.asset.file, disposition: 'attachment')
end
end
end
end
end