If I have...
class Bunny < ActiveRecord::Base
has_many :carrots
end
我该如何在视图中检查@bunny
是否有任何胡萝卜?我想做这样的事情:
<% if @bunny.carrots? %>
<strong>Yay! Carrots!</strong>
<% for carrot in @bunny.carrots %>
You got a <%=h carrot.color %> carrot!<br />
<% end %>
<% end %>
我知道@bunny.carrots?
不能用 -- 有什么可以用的吗?