В настоящий момент я столкнулся с проблемой, пытаясь решить, как мне написать часть модели моей игры.
В настоящее время у меня есть следующее в моем разделе индекса модели:
def index
games_relation = case params[:console].present?
when true then Game.where(:console => params[:console])
else Game
end
@games = games_relation.search(params[:search])
end
Теперь это работает нормально, но я хочу добавить в другой раздел, который смотрит на имя пользователя, поэтому он включает в себя:
user_relation = case params[:username].present?
when true then User.where("username LIKE ?", "#{params[:username]}%")
else User
end
Теперь я представляю, что вставил два цикла в индекс, но как мне поступить в строке @games?
Я пробовал что-то вроде следующего, но нетудача:
def index
games_relation = case params[:console].present?
when true then Game.where(:console => params[:console])
else Game
end
name_relation = case params[:game_name].present?
when true then Game.where("game_name LIKE ?", "#{params[:game_name]}%")
else Game
end
@games = name_relation.games_relation.search(params[:search])
end
У меня в настоящее время есть вызовы games_relation, но как бы мне сделать так, чтобы он вызывал games_relation и user_relation?