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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -