在我的 Rails 3.2.11 和“开发”环境中,当我尝试拥有活动模型时:
class DisponibilityApi
include ActiveModel::Model
attr_accessor :start_time, :end_time
validates :start_time, :end_time, :presence => true
end
我有一个错误:
NameError:未初始化的常量 ActiveModel::Model
但是当我手动包含它时:
class DisponibilityApi
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations
include ActiveModel::Conversion
attr_accessor :start_time, :end_time
validates :start_time, :end_time, :presence => true
end
现在可以了!
我错过了什么吗?
谢谢 !
ActiveModel::Model 是 Rails 4 的新功能,这就是为什么它出现在 Github master 上,但没有出现在 3.x gems 中。如果你查看 Github 上的 3.x 版本分支,它也不在那里。
https://github.com/rails/rails/tree/3-2-stable/activemodel/lib/active_model https://github.com/rails/rails/tree/3-2-stable/activemodel/lib/active_model
对于 Rails 3.x,您需要手动包含每个模块。
要查看它包含的内容,请查看 master 分支中的文件。
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)