views/practice_questionx/index.html.erb file, I want to shuffle certain attributes of the model from the database on each page load. I know I have to get the attributes into an array and call a .shuffle method on them, but I am really struggling with the syntax and how to do that.
<% @practice_questions.each do |practice_question| %>
<%= practice_question.answer_choice_one %>
<%= practice_question.answer_choice_two %>
<%= practice_question.answer_choice_three %>
<%= practice_question.answer_choice_four %>
<%= practice_question.answer_choice_five %>
class PracticeQuestionsController < ApplicationController
before_action :set_practice_quiz, only: [:show, :edit, :update, :destroy]
before_action :set_practice_question, only: [:show, :edit, :update, :destroy]
@practice_questions = PracticeQuiz.all.friendly.find(params[:practice_quiz_id]).practice_questions.order('created_at ASC').paginate(:page => params[:page], per_page: 1)
# first get the practicequiz with its friendly id, passing it its real id, then get all the pracice questions, then paginate it?
@question = PracticeQuestion.find_by(id: params[:id])
@practice_question = PracticeQuestion.find(params[:id])
@practice_quiz = PracticeQuiz.friendly.find(params[:practice_quiz_id])
# Never trust parameters from the scary internet, only allow the white list through.
params.require(:practice_question).permit(:question, :explanation, :flagged, :answer_choice_one, :answer_choice_two, :answer_choice_three, :answer_choice_four, :answer_choice_five, :answer_choice_correct)
create_table "practice_questions", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["practice_quiz_id"], name: "index_practice_questions_on_practice_quiz_id"
Ultimately, I want to shuffle just the five answer choices on each page load, so they show in a random order each time. I've been trying to figure it out for hours and just can't seem to understand how to do it.