You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, you are right, but you have misunderstood something here.
@users is Mongoid::Criteria .
Criteria is like Relation object in ActiveRecord.
In case of Mongoid, the Mongoid::Criteria module is the core object for querying MongoDB. Every time a query is fired, a criteria is created. Once you have a criteria, you can get the elements, executing an actual query to the database, with a method that is supposed to iterate over the elements or return one element, for eg: .to_a, .each, .map, etc.
So here on @users we have already used @users.each in views/home/index.html.erb to fetch the elements from the database.
As a result there is no need to use @users = User.all.to_a , as we are using @users.each, so no error occurs.
In home_controller.rb
index method
@user=User.all.to_a from @user=User.all (According to mongoid documentation) , otherwise user will get error that user is a nil class.
The text was updated successfully, but these errors were encountered: