Can I suggest doing this instead as a helper method, probably in works_helper -- eg, def has_associations?(work) [the condition, with @work changed to work] end -- and then you just do <% if has_associations?(@work) %> around the ul open and close?