by ricardobeat · 14y ago · 0 comments
{{ user.address || "No address on file" }}
The "not so good" code is essentially this, but inside a wrapper in view code. What if you need different markup for a missing address, you either stuff it into a method or change the method's return value to nil... and what if only street_name is missing, not the whole address? It looks like a big mess to me. class User
delegate :street_name, to: :address, prefix: true, allow_nil: true
end
<%= user.address_street_name || "No street name on file" %>