rails if object.nil? then magic '' in views?

前端 未结 8 1368
清歌不尽
清歌不尽 2020-12-23 16:46

This is one of those things, that maybe so simple I\'ll never find it because everyone else already knows it.

I\'ve got objects I have to check for nil in my views s

8条回答
  •  佛祖请我去吃肉
    2020-12-23 17:27

    Another option, which makes sense occasionally...

    If tax_payment.user returns nil, nil.to_s (an empty string) is printed, which is harmless. If there is a user, it will print the user's name.

提交回复
热议问题