내가 달에 사용자를 전송하는 기본 기능이 있습니다레일 모델 컨트롤러 모범 사례
#Action in a controller
def outer_space
user = User.find(params[:id])
user.board_rocket_to_the_moon
end
#user model
def board_rocket_to_the_moon
#put on space suit, climb in rocket, etc.
end
지금, 나는 그들이 여행을 좋아하는 경우에만 달에 사용자를 보내이에 추가 할를.
if 문을 컨트롤러 또는 모델에 넣는 것이 더 나은 이유는 무엇입니까?
#option 1: Put an if in the controller
def outer_space
user = User.find(params[:id])
user.board_rocket_to_the_moon if user.likes_to_travel
end
#option 2: Stick the if in the user model
def board_rocket_to_the_moon
if self.likes_to_travel
#put on space suit, climb in rocket, etc.
return "BLAST OFF"
else
return "There is no way THIS dude is getting on THAT ship."
end
end