I'm using Active Model Serializer and I need to include a parameter that is within the scope of the controller. For example, I'm serializing over posts, but there is a condition between the current_user (variable in PostController) and posts in the Serializer.
class PostSerializer < ActiveModel::Serializer
attributes :id, :active, :favorite
def favorite
if current_user.favorites.find(object.id) != nil
return true
end
end
however, the current_user is undefined. Is there anyway I can send the current_user as a parameter into the Serializer?
thanks a ton!