Forum: Ruby on Rails Questions about changes to Restful Authentication.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ruby F. (Guest)
on 2008-11-03 07:02
(Received via mailing list)
I have a couple of projects with Restful Authentication

The first snippet is from the Git repo today and is supposed to be the
newer code.

    # Store the given user id in the session.
    def current_user=(new_user)
      session[:user_id] = new_user ? new_user.id : nil
      @current_user = new_user || false
    end


  # Store the given user id in the session.
  def current_user=(new_user)
    session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ?
nil : new_user.id
    @current_user = new_user || :false
  end

Why did "@current_user = new_user || :false" become false? and how
did :false work at all.
Why did we stop caring that new_user is a Symbol? and how could that
happen anyway.

Both are somewhat hypothetical questions, but I am curious.

Thanks in advance.
Robert W. (Guest)
on 2008-11-03 18:34
To answer this you would need to look at the other code surrounding
current_user, but a more direct answer is that using the symbol :false
would not represent a boolean false.

You would need to dig deeper into the code to figure out why they did
not want an actual boolean false. My guess is that it was a hack that
they have since been able to implement in a cleaner way allowing them to
use an actual boolean false value.

In any case it's an internal implementation so either way should not
affect your public use of their API (assuming you're not hacking around
their API).

Ruby F. wrote:
> I have a couple of projects with Restful Authentication
>   # Store the given user id in the session.
>   def current_user=(new_user)
>     session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ?
> nil : new_user.id
>     @current_user = new_user || :false
>   end
This topic is locked and can not be replied to.