Rails 如何判断对象是否存在?

jofone · March 03, 2013 · Last by deathdealer replied at March 03, 2013 · 4263 hits

我有一个公司的模型,其 has_one 营业执照模型,如何判断公司的营业执照是否存在?我这样判断: if @company.biz_licence?

结果出错:undefined method `biz_licence?' for #Company:0x007f2614bbcd08

defined? aa and defined? aa.bb

if @comany.biz_licence 即可

if @company.biz_licence.present?可能更好?

#2 楼 @rociiu 谢谢!这样行了! #3 楼 @ericguo if @company.biz_licence.present? 也试过了,可行!谢谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.