jsonapi-serialize

Conditional attributes with jsonapi-serializers throwing TypeError

隐身守侯 提交于 2020-12-14 23:45:39
问题 I am working on a Ruby on Rails project with ruby-2.6.0 and Rails 6. i am working on api part, i have used jsonapi-serializers gem in my app. I want to add conditional attribute in serializer. Controller: class OrderDetailsController < Api::V1::ApiApplicationController before_action :validate_token def show user = User.find_by_id(@user_id) order_details = user.order_details.where(id: params[:id])&.first render json: JSONAPI::Serializer.serialize(order_details, context: { order_detail: true })

Conditional attributes with jsonapi-serializers throwing TypeError

牧云@^-^@ 提交于 2020-12-14 23:40:08
问题 I am working on a Ruby on Rails project with ruby-2.6.0 and Rails 6. i am working on api part, i have used jsonapi-serializers gem in my app. I want to add conditional attribute in serializer. Controller: class OrderDetailsController < Api::V1::ApiApplicationController before_action :validate_token def show user = User.find_by_id(@user_id) order_details = user.order_details.where(id: params[:id])&.first render json: JSONAPI::Serializer.serialize(order_details, context: { order_detail: true })

How to write unit test using rspec for serializer with custom attributes

家住魔仙堡 提交于 2019-12-11 06:17:22
问题 Hi i am working on a RoR project with ruby-2.5.0 and rails 5. I am using the jsonapi-serializers for my api. I have a serializer with custom attribute as follows:- class ReceiptPartialSerializer include JSONAPI::Serializer TYPE = 'receipt' attribute :id attribute :receipt_partials attribute :receipt_partials do receipt_container = [] object.receipt_partials.each do |partial| receipt_partial = {} receipt_partial['id'] = partial.id receipt_partial['image_url'] = 'https:' + partial&.picture&.url