加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Zombies的Rails – 实验3>练习4

发布时间:2020-12-17 02:51:57 所属栏目:百科 来源:网络整理
导读:我尝试解决这个练习2个小时,我找不到解决办法? 有人,请帮忙吗? http://railsforzombies.org/labs/3/exercises/16 练习: Objective In the each block,if a Zombie has more than 1 tweet,print out SMART ZOMBIE Your Database: Zombiesid name graveyard
我尝试解决这个练习2个小时,我找不到解决办法?

有人,请帮忙吗?

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

练习:

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>

解决方法

您正在寻找的代码是:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读