Rails:Object#id 将被弃用;使用对象#object_id

发布于 2024-09-03 07:13:36 字数 689 浏览 7 评论 0原文

可能的重复:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2024-09-10 07:13:36

@customer 或您的 Matching 对象可能为零。 nil.id 是一个已弃用的方法,引用 nil 的对象 ID。

在继续模板的这一部分之前,请检查您获得的 @customerMatching 对象是否包含某些内容,并且应该没问题。

Either @customer or your Matching object is probably nil. nil.id is a deprecated method referring to nil's object ID.

Check that both @customer and the Matching object you get contain something before going ahead with this part of the template, and you should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文