在我的控制器我正在合并两个不同的实例变量的结果为一个实例变量得到这个错误,并收到以下错误:未定义的方法`<<”的零:NilClass而合并实例变量
undefined method `<<' for nil:NilClass
这里是我的控制器代码
@conversational = InterestType.where("institution_id = ? or global = ? and category_id = ?", current_user.profile.institution_id, true, 1).first
@commercial = InterestType.where("institution_id = ? or global = ? and category_id = ?", current_user.profile.institution_id, true, 2).limit(17)
@user_interest_types << @conversational
@user_interest_types << @commercial
我怎样才能克服这个错误,或者有什么好方法如下结果。
- 我想显示第一个会话兴趣类型,然后显示其他17个商业兴趣类型。
'@ user_interest_types'必须是'nil'。在将对象推到它上面之前,请检查并确保已初始化它。 –
@user_interest_types = {}是这样的吗? – chaitanya
不,'@user_interest_types = []' – Mischa