I'm working on a site that shows multiple-choice questions. Users have the ability to add new questions. I want to call the next question from a button, so I need that button to update the page with the next ActiveRecord item.
shuffled_questions = Array.new(Question.ids).shuffle
@question = Question.find(shuffled_questions.pop)
My view shows one question at a time, and I don't want any questions to repeat, which is why I'm pulling them out of an array, but I don't know how to update
@question with the next id in the array from the view.
My first thought was to update the page using AJAX or an OnClick function, but that didn't seem to work.
I've read through other people updating their models and controllers to get the next ActiveRecord item, and I see what they're doing, such as here, but that didn't help me understand how to call the update from the view.
Thanks so much for the help!