fix permalinks serializer with subfolder setups

This commit is contained in:
Régis Hanol 2017-04-05 18:45:01 +02:00
parent 48d9c69117
commit d1c79372d7

View File

@ -1,31 +1,34 @@
class PermalinkSerializer < ApplicationSerializer
attributes :id, :url, :topic_id, :topic_title, :topic_url, :post_id, :post_url, :post_number, :post_topic_title, :category_id, :category_name, :category_url, :external_url
attributes :id, :url, :topic_id, :topic_title, :topic_url,
:post_id, :post_url, :post_number, :post_topic_title,
:category_id, :category_name, :category_url, :external_url
def topic_title
object.try(:topic).try(:title)
object&.topic&.title
end
def topic_url
object.try(:topic).try(:url)
object&.topic&.url
end
def post_url
object.try(:post).try(:url)
# use `full_url` to support subfolder setups
object&.post&.full_url
end
def post_number
object.try(:post).try(:post_number)
object&.post&.post_number
end
def post_topic_title
object.try(:post).try(:topic).try(:title)
object&.post&.topic&.title
end
def category_name
object.try(:category).try(:name)
object&.category&.name
end
def category_url
object.try(:category).try(:url)
object&.category&.url
end
end