In my controller i am merging the results of two different instance variables into one instance variable and i got an following error:
undefined method `<<' for nil:NilClass
Here is my controller code
@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
How can i get over of this error or what is the good way to get following result.
- I want to display first conversational interest type then other 17 commercial interest types.
If you want to append to an array you have two options and here you must pay attention to what you’re adding:
If you use
<<for both operations you end up pushing an array into an array and the resulting structure has multiple layers. You can see this if you callinspecton the result.