rubyでオペレータ& &について何か不足しているはずです(この動作の原因は疑わしい)。RoR 3:before_filterとコントローラのアクションで同じコードが動作しない
このコード: 匿名& & user_signed_in? は、それがapplication_controllerのbefore_filterまたはホームコントローラのアクションにある出力を生成しません。
そして私はなぜunderstantません。
詳細:
Iは、アプリケーションコントローラでこのコードを追加し、それがあろうラン
before_filteranonymous = 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?)}"
として印刷resulteである:
REPONSE : true session: false anonym false is there a curr user: true /// BOTH: true
場合同じコードがホームコントローラの動作にある th e印刷結果は
REPONSE : false session: false anonym false is there a curr user: true /// BOTH: false
私は理解してください。
編集(Klochneの要求に続いて):app_controllerで
:home_controllerで
Anon-class: String REPONSE : true session: false anonym false is there a curr user: true /// BOTH: true
Anon-class: FalseClass REPONSE : false session: false anonym false is there a curr user: true /// BOTH: false
ので1が何らかの理由で、それを文字列として解釈します。
「anon-class:#{anonymous.class.name}」 – klochner
何かが、コードを呼び出して検索/印刷する前にクッキー['anonymous']を 'false'に設定していますあなたがApplicationControllerでそれを呼び出すと、それは文字列に設定されています。これは '&&'演算子とは関係ありません。 – Batkins
私はそのようなものだったと思うが、私はそれを明示的にfalseまたはtrueに設定した唯一の場所以外は何も設定しない。 – Emanuel