If I have...
class Bunny < ActiveRecord::Base
has_many :carrots
end
... how can I check in the view if it @bunnyhas 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 what @bunny.carrots?doesn't work - what would it be?
source
share