搞定关于text_field_with_auto_complete的一个错误(原)

阅读更多
@mathsfan=params[:product][:mathsfan] rescue nil
加一个rescue nil就可以把以下错误给kill掉了:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

虽然这样程序可以正常使用,不过在服务器端却会返回错误warning: else without rescue is useless。
根据我一个网友林子的分析:
@mathsfan=params[:product][:mathsfan]报错是因为没有params[:product]而我调用params[:product][:mathsfan]就是nil[:mathsfan]的错误。改为这样就好了:
@mathsfan=params[:product][:mathsfan] if params[:product]
So happy it!
PS:还要继续恶补基础啊,加油```

你可能感兴趣的:(搞定关于text_field_with_auto_complete的一个错误(原))