Custom Wordpress Serializer and Path, with Specs

This commit is contained in:
Robin Ward
2013-06-28 13:55:34 -04:00
parent 2d6118297d
commit 2deaf8ef98
8 changed files with 137 additions and 42 deletions

View File

@@ -0,0 +1,34 @@
# The most basic attributes of a topic that we need to create a link for it.
class BasicPostSerializer < ApplicationSerializer
attributes :id,
:name,
:username,
:avatar_template,
:created_at,
:cooked
def name
object.user.name
end
def username
object.user.username
end
def avatar_template
object.user.avatar_template
end
def cooked
if object.hidden && !scope.is_staff?
if scope.current_user && object.user_id == scope.current_user.id
I18n.t('flagging.you_must_edit')
else
I18n.t('flagging.user_must_edit')
end
else
object.filter_quotes(@parent_post)
end
end
end