Rails:Object#id 将被弃用;使用对象#object_id
可能的重复:
Rails 主键和对象 ID
非常简单的问题。我的服务器警告我第 37 行将被弃用,特别是:
#Server error:
views/projects/index.html.erb:37: warning: Object#id will be deprecated; use Object#object_id
#Views/projects/index.html.erb:
6: <% for project in @projects do %>
36: <%= project.id %>
37: <%= Matching.find_all_by_customer_id_and_project_id( @customer.id, project.id).id %>
38: <%= @customer.id %>
这是我的困惑。第 36 行 project.id 没有发出警告,因此我认为问题是我在匹配模型上调用 ID。为什么只有匹配报错,而客户或项目没有报错?如何在我的代码中纠正这个问题?
非常感谢。
Possible Duplicate:
Rails primary key and object id
Very quick question. My server is warning me that line 37 will be deprecated, specifically:
#Server error:
views/projects/index.html.erb:37: warning: Object#id will be deprecated; use Object#object_id
#Views/projects/index.html.erb:
6: <% for project in @projects do %>
36: <%= project.id %>
37: <%= Matching.find_all_by_customer_id_and_project_id( @customer.id, project.id).id %>
38: <%= @customer.id %>
Here's my confusion. Line 36 project.id isn't raising a warning, so I assume the issue is that I'm calling ID on the Matching model. Why is it the case that only Matching raising an error and not customer or project? How can I rectify this in my code?
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
@customer
或您的Matching
对象可能为零。nil.id
是一个已弃用的方法,引用 nil 的对象 ID。在继续模板的这一部分之前,请检查您获得的
@customer
和Matching
对象是否包含某些内容,并且应该没问题。Either
@customer
or yourMatching
object is probably nil.nil.id
is a deprecated method referring to nil's object ID.Check that both
@customer
and theMatching
object you get contain something before going ahead with this part of the template, and you should be fine.