ruby - rails active model serializer not doing anything -
i using the gem found here: https://rubygems.org/gems/active_model_serializers
i've created serializer using rails g, added controller return json still returning , not defined attributes - ideas?
module api module v1 class productdetailscontroller < applicationcontroller def show @prod = productprice.joins(:product, :retailer).select("*") render json: @prod, serializer: productdetailserializer end end end end class productdetailserializer < activemodel::serializer attributes :id end thanks.
either query wrong - i´m guessing since defining show method looking this:
module api module v1 class productdetailscontroller < applicationcontroller def show @prod = productprice.joins(:product, :retailer).find(params[:id]) render json: @prod, serializer: productdetailserializer end end end end if intend serialize array of productprice objects need pass each_serializer option.
module api module v1 class productdetailscontroller < applicationcontroller def show @prod = productprice.joins(:product, :retailer).all render json: @prod, each_serializer: productdetailserializer end end end end
Comments
Post a Comment