Rails 3 中 ActiveRecord::RecordNotFound 的替代语法是什么
随着 Rails 3 中 ActiveModel 的引入,调用 ActiveRecord::RecordNotFound 的新方法是什么? ActiveModel::RecordNotFound ?
With the introduction of ActiveModel in Rails 3 whats the new method of calling ActiveRecord::RecordNotFound. ActiveModel::RecordNotFound ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 ActiveModel 的定义 (1):
ActiveRecord 实现 ActiveModel。当 ActiveRecord 无法通过给定 id 或一组 id 找到记录时,它会引发 ActiveRecord::RecordNotFound 异常 (2) 在数据库中。
这意味着不能出现像 ActiveModel::RecordNotFound 这样的异常。
This is the definition (1) of ActiveModel:
ActiveRecord implements ActiveModel. ActiveRecord raises its ActiveRecord::RecordNotFound exception when it can't find record by given id or a set of ids (2) in the database.
This mean there can't be such exception like ActiveModel::RecordNotFound.
ActiveModel 是一组要实现的模块和约定,主要目标是为映射器提供通用接口,不多也不少。所以不,
ActiveRecord::RecordNotFound
仍然是ActiveRecord::RecordNotFound
。RecordNotFound
对每个映射器都没有意义:例如,对于 Mongoid,您将拥有DocumentNotFound
(嗯,Mongoid::Errors::DocumentNotFound
)。ActiveModel is a set of modules and conventions to be implemented, the main goal being providing a common interface to mappers, no more, no less. So nope,
ActiveRecord::RecordNotFound
staysActiveRecord::RecordNotFound
.RecordNotFound
does not make sense for every mapper : with Mongoid for instance, you'll haveDocumentNotFound
(well,Mongoid::Errors::DocumentNotFound
).