Search code examples
ruby-on-rails-4activerecordhas-many

Rails Active Record Displaying Model Row in View Unbidden


Issue: I am relatively new to rails. I figured out how to display data from associated models however the whole table row is being rendered in what looks like an array in the bottom of the div. Any suggestions would be welcome.

 [#<ShortTermGoal id: 1, user_id: nil, contact_id: 4, title: "small blah", description: "blah blah blah ", created_at: "2015-05-31 13:58:31", updated_at: "2015-05-31 13:58:31">]

View Code:

  <div class="group">
    <h3>Personal Goals</h3>
    <div>
      <fieldset>
        <legend>Short Term Goals</legend>
        <div class="row">
          <div class="small-12 columns">
            <ol>
            <%= @contact.short_term_goals.all.each do |short_term_goals| %>
                  <li><strong><%= short_term_goals.title %></strong> <%= simple_format(short_term_goals.description) %> </li>
            <% end %>
            </ol>
          </div>
        </div>
      </fieldset>
      <fieldset>
        <legend>Long Term Goals</legend>
        <div class="row">
          <div class="small-12 columns">
            <%= @contact.long_term_goals.each do |long_term_goals| %>
            <ol>
              <li><strong><%= long_term_goals.title %></strong> <%= simple_format(long_term_goals.description) %></li>
            <% end %>
            </ol>
          </div>
        </div>
      </fieldset>
    </div>
  </div>

Solution

  • Your each loop is wrapped by the wrong type of tag.

     V
    <% @contact.short_term_goals.all.each do |short_term_goals| %>
       <li><strong><%= short_term_goals.title %></strong> <%= simple_format(short_term_goals.description) %> </li>
    <% end %>