rails 4 activerecord TypeError nil is not a symbol

后端 未结 2 1675
无人及你
无人及你 2021-01-05 02:36

It appears a table in sql server is placing nil in the select statement. I have no idea how to fix this, and if I switch to any other table, I can easily acquir

2条回答
  •  离开以前
    2021-01-05 03:23

    While I still believe this is a bug in active record, I was able to get around it with the https://github.com/rails-api/active_model_serializers gem. This gem overrides to_json eliminated the need for the bug code in active record to be called.

    anyone else have a better answer?

    Updated Controller:

    class V1::DealsController < ApplicationController
    
        def by_mall_id
          deals = Deal.where(mallid: params[:id]).first
          render json: deals, serializer: V1::DealSerializer
        end
    
    end
    

    My new DealSerializer:

    class V1::DealSerializer < ActiveModel::Serializer
        attributes :MALLID
    
        def MALLID
          object.mallid
        end
    
    end
    

提交回复
热议问题