ruby에서 & & 연산자에 대한 내용을 놓치고 있어야합니다 (이 동작의 원인이라고 생각됩니다)?RoR 3 : before_filter 및 컨트롤러 동작에서 코드가 동일하게 동작하지 않음
다음 코드는 익명 & & user_signed_in? 은 application_controller의 before_filter 또는 홈 컨트롤러의 동작에있는 출력을 생성하지 않습니다.
그리고 나는 왜 그렇게 생각하지 않습니다.
REPONSE : true session: false anonym false is there a curr user: true /// BOTH: true
경우] :
세부 사항 : A는
anonymous = cookies['anonymous']
fresh_session = cookies['session_id'].nil?
rep = (fresh_session || (anonymous && user_signed_in?))
puts "REPONSE : #{rep} session: #{fresh_session} anonym #{anonymous} is there a curr user: #{user_signed_in?} /// BOTH: #{(anonymous && user_signed_in?)}"
before_filter 인쇄 resulte 그대로
나는 응용 프로그램 컨트롤러에이 코드를 추가하고 그것을 실행을 것 동일한 코드가 홈 컨트롤러의 동작에 있음 th 전자 인쇄 결과는 다음과 같습니다.
REPONSE : false session: false anonym false is there a curr user: true /// BOTH: false
이해해주세요. (Klochne의 요청에 따라)
편집 : app_controller에서
:
Anon-class: FalseClass REPONSE : false session: false anonym false is there a curr user: true /// BOTH: false
그래서 하나가 어떤 이유로 문자열로 해석 home_controller에서
Anon-class: String REPONSE : true session: false anonym false is there a curr user: true /// BOTH: true
.
이것을 추가하고 두 위치에서 모두 시도하십시오 : "anon-class : # {anonymous.class.name}" – klochner
뭔가 검색/인쇄하기 위해 코드를 호출하기 전에 뭔가 [ '익명'] 쿠키를 'false'로 설정했습니다 homeController에서는 ApplicationController에서 호출 할 때 문자열로 설정됩니다. 이것은'&& '연산자와 아무런 관련이 없습니다. – Batkins
나는 그것이 그랬 으면 좋겠지 만, 아무것도 명시 적으로 false 또는 true로 설정 한 유일한 장소를 제외하고는 쿠키를 설정하지 않습니다. – Emanuel