
I’ve a rails view that outputs the content of a model value in this case agenda.subject
Checking the db the bottom two items are not in the db, I know :id and the blank are but what in my code could cause it to display like this
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>
and the users controller
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
I excluded the first couple of records they looked normal but its those last 2 that are weird
Output from @agendas.inspect and @agendas.length
I am using faker to create a sample data fro the app, possibly culprit?
You’re calling
which will append a blank, unsaved agenda to the list of agendas whenever a signed in used views this page. It’s not clear from your question what you do with
@agendabut you may be better off just setting that toAgenda.new