Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails for Zombies - Lab 3 › Exercise 4

I tried solving this exercise for 2 hours and I just can't find a solution?

Anybody, help please?

http://railsforzombies.org/labs/3/exercises/16

The exercise:

Objective

In the each block, if a Zombie has more than 1 tweet, print out SMART ZOMBIE

Your Database:

Zombies
id  name  graveyard
1   Ash   Glen Haven Memorial Cemetary
2   Bob   Chapel Hill Cemetary
3   Jim   My Fathers Basement

Tweets
id  status                                    zombie_id
1   Where can I get a good bite to eat?       1
2   My left arm is missing, but I don't care  2
3   I just ate some delicious brains          3
4   OMG, my fingers turned green.             1

The view code:

<% zombies = Zombie.all %>

<ul>
  <% zombies.each do |zombie| %>
    <li>
      <%= zombie.name %>
      # add if statement here
    </li>
  <% end %>
</ul>
like image 693
Ron Avatar asked Feb 26 '23 01:02

Ron


1 Answers

The code you are looking for is:

<% if zombie.tweets.count > 1 %>
SMART ZOMBIE
<% end %>
like image 61
Michelle Tilley Avatar answered Feb 27 '23 14:02

Michelle Tilley