저는 현재 게임 모델의 섹션을 작성하는 방법을 해결하려고 할 때 문제가 발생했습니다.모델에 두 개의 if 문을 표시합니다.
저는 현재 모델의 내 데프 인덱스 부분에 다음과 같습니다
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를 호출 할 수 있도록 내가 어떻게 할 것이가?
죄송합니다, 나는 당신의 문제를 이해하지 못했지만, 한 가지 내가 확실히 말할 수있다 : 당신은 두 가지 옵션이 경우 case 문을 사용하지 말아야합니다 . 대신에'if ... else'를 사용하십시오. –
안녕하세요 저는 방금 시도한 내용과 시도하려는 내용을 알려주기 위해 제 질문을 업데이트했습니다. – user1222136
게임과 사용자 간의 관계를 설명 할 수 있다면 2 초 안에이 내용을 그려 보겠습니다. – TomDunning