I have an array of video names, I want to grab a random video name from this array. But when I call a helper method to do all this, I get the same random number, and random video each time.
I believe this is because the helper method is only called once even though I'm trying to "call it" multiple times, it's just the results of that method that are "called" multiple times.
So what I'm thinking is to find a way to send a JavaScript variable to the helper method, but I have no idea (nor does Google) of how best to do this.
To keep it simple, with just trying to obtain a new random number each time:
JS:
function randomNumber() {
alert("<%= random_number %>");
}
setTimeout(function(){
randomNumber();
}, 2000);
html.erb:
helper_method :random_number
def random_number
rand(0..10)
end
The same random number is shown each time.