mardi 4 octobre 2016

Rails Random Number Between 0 and 3 always 0 or 1

I am using random numbers to try to call a random partial. I have the erb:

<% @random_partial = 'man_tests/test' + [*0..3].sample %>
<%= render partial: @random_partial %>

But I have also tried rand(0..3).round.to_s and the same thing happens: No matter how many times I click the button, it shows me _test0.html.erb or _test1.html.erb. I have tried enough that it would be statistically crazy if it was by chance that I only ever got these two. I even tried switching the content from _test0 and _test3 to see if it was somehow causing the problem and I still only got the ones named 0 and 1.

Can anyone help me figure out what's causing this problem?

Aucun commentaire:

Enregistrer un commentaire