ActiveRecord Virtual Attributes treaded as a record attributes

前端 未结 6 1491
小鲜肉
小鲜肉 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:24

    Simply implement #to_json yourself then:

    class Location < ActiveRecord::Base
      def to_json(options={})
        options[:methods] ||= []
        options[:methods] << :event_oid
        super(options)
      end
    end
    

提交回复
热议问题