rails/daylight/serializers.rb
##
# Create a simple serializer that sends all attributes and has_one and belongs_to associations
Create a simple serializer that sends all attributes and has_one and belongs_to associations
Create a simple serializer that sends all attributes and has_one and belongs_to associations
def auto_generate_serializer
      model_class = self.class
      @auto_generated_serializer ||=
        Class.new(ActiveModel::Serializer) do
          embed :ids
          attributes(*model_class.column_names.map(&:to_sym))
          model_class.reflections.each_pair do |name, reflection|
            options = reflection.options
            case reflection.macro
            when :has_one, :belongs_to
              has_one name, key: options[:foreign_key], through: options[:through]
            end
          end
        end
    end
def auto_generate_serializer model_class = self . class @auto_generated_serializer ||= Class . new ( ActiveModel :: Serializer ) do embed :ids attributes ( * model_class . column_names . map ( & :to_sym ) ) model_class . reflections . each_pair do | name , reflection | options = reflection . options case reflection . macro when :has_one , :belongs_to has_one name , key : options [ :foreign_key ] , through : options [ :through ] end end end end
Create a simple serializer that sends all attributes and has_one and belongs_to associations
Create a simple serializer that sends all attributes and has_one and belongs_to associations