This is my code:
<% question.answers.each do |answer| %>
<li><%= answer.content %></li>
<% end %>
I want to order the answer objects randomly. What would be the most efficient way to do so considering the amount of possible answers is less than say 10?
You can use the shuffle
method like this:
question.answers.shuffle.each do |answer|
How about this
<% question.answers.shuffle.each do |answer| %>
<li><%= answer.content %></li>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With