ActiveRecord Virtual Attributes treaded as a record attributes

前端 未结 6 1460
小鲜肉
小鲜肉 2021-01-02 04:54

I am running into a problem with to_json not rendering my virtual attributes

class Location < ActiveRecord::Base
    belongs_to :event
    before_create :g         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 05:23

    I tried François Beausoleil's answer and got it to work after modifying to_json to as_json

    def as_json(options={})
      options[:methods] ||= []
      options[:methods] << :class_to_s
      super(options)
    end
    

提交回复
热议问题