2013-03-20 58 views

回答

1

@user.profile.age == 0 ? "Unknown" : @user.profile.age应该工作。

+0

谢谢。这工作完美:) – HUSTEN 2013-03-20 06:24:56

+0

太棒了!继续并接受这个答案,以便堆栈溢出可以看到它关闭。 – piersadrian 2013-03-20 06:26:24

+0

我会的。我需要再等两分钟。请等待 – HUSTEN 2013-03-20 06:29:25

0

试试这个

@user.profile.age > 0 ? @user.profile.age : "Unknown" 
0

您可以尝试使用如下

([email protected](:age) || @user.profile.try(:age)== 0) ? "Unknown" : @user.profile.age 
0

如果系统发现年龄为空或空,那么你的代码将产生错误。我希望这会起作用,从而避免崩溃。

(@ user.profile.age == 0)|| ([email protected]?)? “未知”:@ user.profile.age

相关问题