ruby on rails - ActiveModelSerializer conditional association rendering -
in spree api application, want render associated comments of product if user admin. else render product detail.
i'm using 0.10.0.rc2 of active_model_serializers
gem 'active_model_serializers', '~> 0.10.0.rc2' i'm overriding product serializer of spree follows:
spree::productserializer.class_eval attributes :stock_available has_many :comments, serializer: myapplication::commentserializer # http://www.rubydoc.info/gems/active_model_serializers#associations def filter(keys) # <--- option 1 keys.delete(:comments) unless scope.admin? keys end def include_comments? # <--- option 2 scope.admin? end end here comments polymorphic table. none of 2 option seems working. idea whats wrong here?
i went through railscast episode on active-model-serializer. doesn't seems working here.
also strange thing is, when put binding.pry in either of these 2 methods, request @ /api/products/:id doesn't pause @ binding.pry.
thanks
Comments
Post a Comment