Zombie Rails - Lab 3> Exercise 4

I tried to solve this exercise for 2 hours, and I just can not find a solution?

Can someone please help?

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

The exercise:

goal

In each block, if Zombie has more than 1 tweet, print 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 

View Code:

 <% zombies = Zombie.all %> <ul> <% zombies.each do |zombie| %> <li> <%= zombie.name %> # add if statement here </li> <% end %> </ul> 
+4
source share
4 answers

The code you are looking for is:

 <% if zombie.tweets.count > 1 %> SMART ZOMBIE <% end %> 
+8
source

Any idea why this won't work? I'm trying to make another call to get all the tweets from this zombie.

 <% t = Tweet.where(:id => zombie.id) %> <% if t.size > 1 %> <%= 'SMART ZOMBIE' %> <% end %> 

The error I am getting is:

 #<ActionView::Template::Error: uninitialized constant ActionView::CompiledTemplates::Tweet> 

Or do you think the tutorial is designed to work with only one solution, and you cannot call to access the tweet table?

0
source

Original tip # 1

Use the .size or .count methods to find out if a zombie has more than one tweet.

Original tip # 2

Possible correct answer:

 <ul> <% zombies.each do |zombie| %> <li> <%= zombie.name %> <% if zombie.tweets.size > 1 %> SMART ZOMBIE <% end %> </li> <% end %> </ul> 
0
source
 <ul> <% zombies.each do |zombie| %> <li> <%= zombie.name %> <% if zombie.tweets.size > 1 %> <em> SMART ZOMBIE </em> <% end %> </li> <% end %> </ul> 

Printing Exercise

0
source

Source: https://habr.com/ru/post/1340541/


All Articles