Activerecord 无表模型的关联

Activerecord 无表模型的关联,activerecord,ruby-on-rails-4,associations,Activerecord,Ruby On Rails 4,Associations,我一直在尝试在前端实现关联,但目前的应用程序没有任何数据库直接连接到网站,因此我们不能使用ActiveRecord,只能使用ActiveModel来支持模型的验证和核心功能。现在,由于我们需要使用嵌套属性,我们将与对象一起发送,与用户关联的地址,因此我们需要首先在相应的模型上定义关联。但在定义了关联之后,它抛出了用户模型上未定义方法“has_many”的异常。我目前正在搜索如何在我们的网站上实现它,并实现嵌套属性的逻辑。 如果您能向我推荐与此相关的任何内容,或者您过去曾遇到过此类问题,那将是非常

我一直在尝试在前端实现关联,但目前的应用程序没有任何数据库直接连接到网站,因此我们不能使用ActiveRecord,只能使用ActiveModel来支持模型的验证和核心功能。现在,由于我们需要使用嵌套属性,我们将与对象一起发送,与用户关联的地址,因此我们需要首先在相应的模型上定义关联。但在定义了关联之后,它抛出了用户模型上未定义方法“has_many”的异常。我目前正在搜索如何在我们的网站上实现它,并实现嵌套属性的逻辑。 如果您能向我推荐与此相关的任何内容,或者您过去曾遇到过此类问题,那将是非常棒的。
我也尝试过使用gem的方法,但不适合我。我还添加了一个tabless.rb

tabless.rb

class Tableless < ActiveRecord::Base     
  def self.column(name, sql_type = nil, default = nil, null = true)
    columns << ActiveRecord::ConnectionAdapters::Column.new( name.to_s, default, sql_type.to_s, null )
  end

  def self.columns()
    @columns ||= [];
  end

  def self.columns_hash
    h = {}
    for c in self.columns
    h[c.name] = c
    end
    return h
  end

  def self.column_defaults
    Hash[self.columns.map{ |col|
    [col.name, col.default]
    }]
  end
  def self.descends_from_active_record?
    return true
  end
  def persisted?
    return false
  end
# override the save method to prevent exceptions
end
类无表columns您似乎忘记调用该方法了

has_no_table
在您的模型上,根据。在他们的例子中:

class ContactMessage < ActiveRecord::Base
  has_no_table
  column :name, :string
  column :email, :string
  validates_presence_of :name, :email
end
class ContactMessage

希望这有帮助。=)

使用时有什么问题?
class ContactMessage < ActiveRecord::Base
  has_no_table
  column :name, :string
  column :email, :string
  validates_presence_of :name, :email
end