methods - Rails: How to check for attributes with polymorphic? (Prints okay, won't allow conditional) -


going accessing user attributes (name, e-mail, avatar, etc) comments section ("identify user commenter"), why let me print out values not use them in conditionals?

why can this? (prints avatar next comment should)

<%= image_tag comment.user.avatar.url, size: "64" %>

but not this? (won't let me check if there's avatar or not first)

<% if comment.user.avatar.url.empty/blank/nil/present? %>

so if commenter hasn't uploaded avatar yet, returns:

undefined method \'avatar\' nil:nilclass

is there method need define in controller, or scope in model, or there way of checking in situation?

thank you.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -