country
属性的默认值为 nil。
在国家表中,一些记录有image_url
,其余记录的country
属性为零。
所以我在助手中编码了这个
def image(user)
if user.country.image_url
image_tag "flags/#{user.country.image_url}.png"
end
end
但是,它在image_url
为 nil时返回错误
Something went wrong
我该如何解决?