Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:54:25+00:00 2026-05-27T22:54:25+00:00

I must be missing something out about the operator && in ruby (which I

  • 0

I must be missing something out about the operator && in ruby (which I doubt is the cause of this behavior)?

This code:
anonymous && user_signed_in?
does not generate the output wether it is in the before_filter of the application_controller or in an action of the home controller.

And I do not understant why.

Details:

I added this code in the application controller and it would runs as a before_filter

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?)}"

the printed resulte is:

REPONSE : true  session: false  anonym false is there a curr user: true /// BOTH: true

If the same code is in an action of the home controller
the printed result is:

REPONSE : false  session: false  anonym false is there a curr user: true /// BOTH: false

Please help me understand.

Edit (Following Klochne’s request):

In the app_controller:

Anon-class: String REPONSE : true  session: false  anonym false is there a curr user: true /// BOTH: true

In the home_controller

Anon-class: FalseClass REPONSE : false  session: false  anonym false is there a curr user: true /// BOTH: false

So one interprets it as a string for some reason.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:54:26+00:00Added an answer on May 27, 2026 at 10:54 pm

    Try setting the variables in the before filter as instance variables instead of local variables. That way they will persist and stay set in the controller action as opposed to instance variables. So change the method being called with before_filter to be this:

    @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?)}"
    

    And then in your controller you can just put this line again:

    puts "REPONSE : #{@rep}  session: #{@fresh_session}  anonym #{@anonymous} is there a curr user: #{user_signed_in?} /// BOTH: #{(@anonymous && user_signed_in?)}"
    

    And it should print out the same results. Local variables are only accessible from within the block of its initialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must be missing something about how this works, because I can't figure this
I must be missing something very simple, but can't find the answer to this.
Now I must be missing something here, as this seems a very basic issue
I know SQL well but I must be missing something really dumb here. This
This seems very basic and I must be missing something, but here goes anyways...
I tried the solution from this thread , but I must be missing something
I've scoured Google and this site pretty extensively, and I must be missing something.
I must be missing something... So I am in the process of figuring out
I know I must be missing something, but can't figure out what. When I
I must be missing something, but I can't seem to figure out how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.