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
1 changed files with 11 additions and 8 deletions

View File

@ -1,31 +1,34 @@
class PermalinkSerializer < ApplicationSerializer 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 def topic_title
object.try(:topic).try(:title) object&.topic&.title
end end
def topic_url def topic_url
object.try(:topic).try(:url) object&.topic&.url
end end
def post_url def post_url
object.try(:post).try(:url) # use `full_url` to support subfolder setups
object&.post&.full_url
end end
def post_number def post_number
object.try(:post).try(:post_number) object&.post&.post_number
end end
def post_topic_title def post_topic_title
object.try(:post).try(:topic).try(:title) object&.post&.topic&.title
end end
def category_name def category_name
object.try(:category).try(:name) object&.category&.name
end end
def category_url def category_url
object.try(:category).try(:url) object&.category&.url
end end
end end