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

ssc*_*rus 2 ruby-on-rails object deprecated

可能重复:
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 %>
Run Code Online (Sandbox Code Playgroud)

这是我的困惑.第36行project.id没有发出警告,所以我假设问题是我在匹配模型上调用ID.为什么只匹配引发错误而不是客户或项目呢?我怎样才能在我的代码中纠正这个问题?

非常感谢.

Mat*_*chu 5

无论是@customer或者你的Matching对象可能是零.nil.id是一个不推荐使用的方法,引用了nil的对象ID.

在继续使用模板的这一部分之前,检查两者@customerMatching你得到的对象是否包含一些内容,你应该没问题.