2

is It possible get a shuffle/random of a collection from action in controller.

def action
 #pseudocode something like the next:
 @objects = Object.random
 respond_to do |format|
  format.html
 end
end

I now can get shuffle from my view, with:

<% @objects.shuffle.each do |microfunc| %>
.
.
.
<% end %>

On view is possible with each or for loop. I don't want use loop to get random Object from one collection.

How can I get random objects inside Mongoid::Criteria from my action controller?

hyperrjas
  • 10,666
  • 25
  • 99
  • 198

1 Answers1

0

There isn't a great way. Your choices:

Community
  • 1
  • 1
Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109