I have two models, Tenant and Property. Property has many Tenants, and Tenant belongs to Property.
I want to write a validation that validates the presence of a tenant unless the property is vacant. This is my code:
validates :tenants, :presence => true, :unless => :vacant?
It seems to make sense, but I can still add a tenant to a property having already stated it as vacant. I'm not sure what other code you'd need to see.
<% @properties.each do |property| %>
<tr>
<td><%= property.street_address %></td>
<td><%= property.city %></td>
<td><%= property.postcode %></td>
<td><%= display_vacant(property) %></td>
<td><%= property.tenants.collect(&:first_name).to_sentence %></td>
</tr>
<% end %>
As always, thanks for any feedback.
Edit: I'm not allowed to post images because I'm a new user, but here's a visual representation of what I want http://cl.ly/202r3j1c1Y1C2d2s0F1R