Ruby on rails Rails在我的模型视图中显示一个空值和一个id

Ruby on rails Rails在我的模型视图中显示一个空值和一个id,ruby-on-rails,activerecord,erb,Ruby On Rails,Activerecord,Erb,我有一个rails视图,它在本例中输出模型值的内容agenda.subject 检查DB底部两个项目不在DB中,我知道:ID和空白是什么,但是在我的代码中什么可以使它显示像这样的< /P> users/index.html.erb <div class="row"> <div class="span8"> <%= render 'agendas/agenda_form' %> <% if @user.agendas

我有一个rails视图,它在本例中输出模型值的内容agenda.subject

检查DB底部两个项目不在DB中,我知道:ID和空白是什么,但是在我的代码中什么可以使它显示像这样的< /P> users/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>

议程()
_agenda.html.erb部分
  • 和用户控制器

    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
    
    class UsersController
    。。。。用户id:1,创建于:“2012-05-17 15:52:22”,更新于:“2012-05-17 15:52:22”>,#]8

    [code>,,,,,,,,,,,,,,,,,,,,,,,,,]8

    我排除了前两张看起来正常的唱片,但最后两张却很奇怪 @agents.inspect和@agents.length的输出

    我正在使用faker为应用程序创建示例数据,可能是罪魁祸首?

    谢谢-

    鉴于您的测试数据:

    [#<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>]
    
    [#,
    #, 
    #, 
    #, 
    #, 
    #, 
    #, 
    #]
    
    看起来罪犯就在数据里。我建议您确认您正在生成您认为是的数据。

    您正在呼叫

    current_user.agendas.build current_user.agendas.build
    

    每当登录用户查看此页面时,将在议程列表中追加一个空白的、未保存的议程。您的问题不清楚您如何处理
    @agenda
    ,但您最好将其设置为
    agenda。新建

    您可以打印
    @agenda.检查
    @agenda.在调用循环之前,长度
    是什么?使用上述请求编辑的问题。似乎这样做了,更改为@议程= AgEn.New,不知道它为什么工作,但副问题,CurrnEnUsSer.AgEnthas.Bug如何生成空白的未保存的AgdiaAd:Bug所做的事情:它将一个未保存的议程添加到集合中