Привет Я создаю игровой контроллер для отображения Q/A игрынеопределенный метод `<<» для # <Ответ :: ActiveRecord_Relation: 0x007fada31c7430>
И я блокированы <<
, вот код
def play
lvlup(lvl)
if lvl == 1
set_questions
else
get_questions
end
@answers = Answer.where.not(id: question.answer_id).limit(2).order("RANDOM()")
@answer ||= []
@answers << question.answer
@answers = @answers.shuffle
render 'play'
end
Я создаю массив, и я отвечу на соответствующий ответ в глобальных ответах, которые я хочу отобразить 4 Макс.
Почему здесь не указано?
Вот весь код
class GamesController < ApplicationController
attr_accessor :lvl
def welcome
end
def congrat
end
def play
lvlup(lvl)
if lvl == 1
set_questions
else
get_questions
end
@answers = Answer.where.not(id: question.answer_id).limit(2).order("RANDOM()")
@answer ||= []
@answers << question.answer
@answers = @answers.shuffle
render 'play'
end
def loose
@question = Question.find(params[:question])
flash.now[:alert] = "Miss..."
render 'loose'
end
def check
@lvl = params[:lvl].to_i
answer_id = params[:id].to_i
question = Question.find(params[:question])
if @lvl == lvlmax
render action: 'congrat' and return
elsif answer_id == question.answer_id
flash.now[:notice] = "Well done !"
play
else answer_id != question.answer_id
loose
end
end
private
def lvlup(value)
@lvl = 1 + value.to_i
end
def lvlmax
@lvlmax = Question.all.count
end
def set_questions
@questionsids = []
Question.all.shuffle.each do |d|
@questionsids << d.id
end
cookies[:questions] = @questionsids
end
def get_questions
@questions = cookies[:questions].split('&')
end
def questions
@questions = cookies[:questions]
end
def question
@question = Question.find(questions[lvl])
end
end
Спасибо за помощь.
Вы имеете в виду, что я меняю «RANDOM» на «RAND»? Но он снова прерывает ошибку в моем коде. Сделайте это правильно для вас? –