Reputation: 1525
When migrating from rails 4.2.6
to 5.0.1
, I am getting some errors:
undefined method `push' for #<User::ActiveRecord_Relation:
while doing:
@users = User.includes(:account).order(:last_name)
@users.push(new_user)
Upvotes: 1
Views: 381
Reputation: 3080
ActiveRecord::Associations::AssociationCollection#push
has been deprecated and removed from ActiveRecord 5
. You may try to convert relation to array before pushing:
@users = User.includes(:account).order(:last_name).to_a
@users.push(new_user)
or find similar method available in ActiveRecord 5. For example there is concat method:
@users = User.includes(:account).order(:last_name)
@users.concat([new_user])
Upvotes: 0
Reputation: 23661
One point to note here is @users
is ActiveRecord
relation. There is no such method push
for ActiveRecord
relation.
push
method is supported by Array
, So you can convert the result into an array and then push the new_user
in the resulting `Arraya
@users = User.includes(:account).order(:last_name)
@users.to_a.push(new_user)
Upvotes: 1