Rails 3 ActiveModel:不能直接包含 ActiveModel::Model [英] Rails 3 ActiveModel: cannot include ActiveModel::Model directly

查看:33
本文介绍了Rails 3 ActiveModel:不能直接包含 ActiveModel::Model的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Rails 3.2.11 和开发"环境中,当我尝试使用活动模型时:

In my Rails 3.2.11 and "development" environment when I try to have an active model:

class DisponibilityApi
  include ActiveModel::Model

  attr_accessor :start_time, :end_time 
  validates :start_time, :end_time, :presence => true

end

我有一个错误:

NameError: 未初始化的常量 ActiveModel::Model

NameError: uninitialized constant ActiveModel::Model

但是当我手动包含它时:

But when I include it manually:

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 版本分支,它也不存在.

ActiveModel::Model is new for Rails 4, which is why it shows up on Github master, but not in the 3.x gems. If you look in the 3.x version branches on Github it is not there either.

https://github.com/rails/rails/tree/3-2-stable/activemodel/lib/active_model

对于 Rails 3.x,您需要手动包含每个模块.

For Rails 3.x you will need to include each of the modules manually.

要查看它包含的内容,请查看 master 分支中的文件.

To see what it includes, check out the file in the master branch.

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb

这篇关于Rails 3 ActiveModel:不能直接包含 ActiveModel::Model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆