Rails: each at random

This is my code:

<% question.answers.each do |answer| %> <li><%= answer.content %></li> <% end %> 

I want to arrange response objects randomly. What would be the most efficient way to do this, given the number of possible answers is less than 10?

+6
source share
2 answers

You can use the shuffle method:

 question.answers.shuffle.each do |answer| 
+14
source

How about this

 <% question.answers.shuffle.each do |answer| %> <li><%= answer.content %></li> <% end %> 
+3
source

All Articles