27 行
464 B
Ruby
27 行
464 B
Ruby
# frozen_string_literal: true
|
|
|
|
|
|
module PostCompactRepr
|
|
module_function
|
|
|
|
def base post
|
|
return nil if post.nil?
|
|
|
|
{
|
|
id: post.id,
|
|
title: post.title,
|
|
url: post.url,
|
|
thumbnail_url: thumbnail_url(post) }
|
|
end
|
|
|
|
def thumbnail_url post
|
|
return nil unless post.thumbnail.attached?
|
|
|
|
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
|
post.thumbnail,
|
|
only_path: false)
|
|
rescue
|
|
nil
|
|
end
|
|
end
|