ruby - Rails: Check has_many in View -
if have...
class bunny < activerecord::base has_many :carrots end
...how can check in view if @bunny
has carrots? want this:
<% if @bunny.carrots? %> <strong>yay! carrots!</strong> <% carrot in @bunny.carrots %> got <%=h carrot.color %> carrot!<br /> <% end %> <% end %>
i know @bunny.carrots?
doesn't work -- would?
<% if @bunny.carrots.any? %> <strong>yay! carrots!</strong> <% carrot in @bunny.carrots %> got <%=h carrot.color %> carrot!<br /> <% end %> <% end %>
Comments
Post a Comment