我有一个 Rails 视图,在这种情况下输出模型值的内容议程.主题
检查数据库,底部两项不在数据库中,我知道 :id 和空白是,但我的代码中的内容可能导致它像这样显示
用户/index.html.erb
<div class="row">
<div class="span8">
<%= render 'agendas/agenda_form' %>
<% if @user.agendas.any? %>
<h2>Agendas (<%= @user.agendas.count %>)</h2>
<ol class="agendas">
<%= render @agendas %>
</ol>
<% end %>
</div>
</div>
the _agenda.html.erb partial
<li>
<span class="content"><%= agenda.subject %></span>
<%= link_to 'delete', agenda, method: :delete,
confirm: "You Sure?",
title: agenda.subject %>
</li>
和用户控制器
class UsersController < ApplicationController
before_filter :authenticate_user!
def index
@user = current_user
@agenda = current_user.agendas.build if signed_in?
@agendas = current_user.agendas
end
end
.... user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #] 8
[#<Agenda id: 49, subject: "Ut qui vel eos quia vitae.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: 43, subject: "Enim dolorem.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: 37, subject: "Rerum architecto est nihil totam.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: 31, subject: "Non.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: 25, subject: "Libero enim et explicabo.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: 19, subject: "Et molestiae et quia saepe quia.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: 7, subject: "Eum consectetur iste.", due_date: nil, completed: nil, user_id: 1, created_at: "2012-05-17 15:52:22", updated_at: "2012-05-17 15:52:22">, #<Agenda id: nil, subject: nil, due_date: nil, completed: nil, user_id: 1, created_at: nil, updated_at: nil>] 8
我排除了前几条记录,它们看起来很正常,但最后两条记录很奇怪来自@agendas.inspect 和@agendas.length 的输出
我正在使用 faker 为应用程序创建示例数据,可能是罪魁祸首?