1
ActiveRecord에서 다음 모델 클래스를 사용하고 있습니다. 이 클래스에 해당하는 ActiveModel을 작성하는 방법은 무엇입니까?레일에 ActiveModel 객체를 만드는 방법 3
class Recommendation < ActiveRecord::Base
def self.columns() @columns ||= []; end
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
column :from_email, :string
column :to_email, :string
column :article_id, :integer
column :message, :text
serialize :exception
validates_format_of :from_email, :to_email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
validates_length_of :message, :maximum => 500
belongs_to :article
end
이유에서 찾을 수 있습니까? 'Recommendation'은 데이터베이스를 뒷받침하지 않습니까? –
단지 임시 개체입니다. 예상 된 작업이 완료 되 자마자 개체를 파괴하고 있습니다. DB에 그 데이터를 저장하고 싶지 않습니다. – Achaius
맞아요,'ActiveModel'은 이것에 대한 좋은 선택입니다. –