If I have…
class Bunny < ActiveRecord::Base has_many :carrots end
…how can I check in the View if @bunny has any carrots? I want to do something like this:
<% if @bunny.carrots? %> <strong>Yay! Carrots!</strong> <% for carrot in @bunny.carrots %> You got a <%=h carrot.color %> carrot!<br /> <% end %> <% end %>
I know @bunny.carrots? doesn’t work — what would?
1 Answer