Wat*_*ink 2 ruby activerecord ruby-on-rails
我们有自定义模型。它可以在没有数据库的情况下工作,并且包含来自活动记录的一些混合:
class Node
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :title, :content
validates_presence_of :title, :content
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
def save
# we want to run validations here
end
end
Run Code Online (Sandbox Code Playgroud)
通过谷歌搜索可以使用@object.validate,但是它抱怨没有这种方法。
请帮忙。