Using Rails and Mongoid.
It would be easier to put down the code for explaination:
foo = User.all.to_a
Trying to format into acceptable data in my Javascript. But in my iteration:
var dump = []
<%= foo.each do |boop| %>
dump.push( /*some formatted data using boop/*)
<% end %>
The result dump contains the acceptable format except the document objects are also added at the end of the array.
For instance, using the rails console:
foo.each do |boop|
print "#{boop.email}\n"
end
Prints out the emails. Then at the end, prints out every single document object in one line.
My output from directly above:
hobbes203@gmail.com
...
// Prints out emails until end
[#<User _id: 50edd7fe021823ea20000001, _type: nil, email: "hobbes203@gmail.com", password_digest: "$2a$10$xXixV8MlqGco0Qq7j5jQaOkXBWQ9cLgQ7yEOtQruxq.HiYg8GOJ4y", phone: nil, firstName: nil, lastName: nil, employNum: nil, dateMade: nil, role_id: "50edd7da021823db20000001">, ... #prints out rest of users in line.
The array size and count in db are the same. I also checked the array using last. I’m thinking of using a count iterator by just taking the length of the array, but I’m very curious as to why this is happening.
the print out you’re seeing is the return value of the operation. eg.
You can surpress this by passing “;0” after the end of the block which would still print the output but would change the return to zero.