您的问题是这Something
是一个抽象类:
class Something < ApplicationRecord
self.abstract_class = true # <-------------------------
抽象类并不意味着直接实例化,您应该对它们进行子类化并实例化子类。该abstract_class
属性或多或少是一种在不调用 STI(单表继承)的情况下对模型进行子类化的方法。
要么Something
用作第二个数据库中模型的基类,要么删除它self.abstract_class = true
以使其成为“真正的”模型类。
至于您的no implicit conversion of nil into String
错误来自哪里,请记住,抽象模型类没有表名并且无法实例化,来自文档:
class Shape < ActiveRecord::Base
self.abstract_class = true
end
Polygon = Class.new(Shape)
Square = Class.new(Polygon)
Shape.table_name # => nil
Polygon.table_name # => "polygons"
Square.table_name # => "polygons"
Shape.create! # => NotImplementedError: Shape is an abstract class and cannot be instantiated.