10/12 Please help me understand the difference:


I got an error message: no implicit conversion of Symbol into Integer

Upon close examination, I realized what caused the error: I added an extra :before session But I don't understand why:

#My code:

  def current_user
     @current_user ||= User.find(:session[:user_id]) if session[:user_id]

#The correct code:

   def current_user
      @current_user ||= User.find(session[:user_id]) if session[:user_id]

Thanks in advance!


Hi @pymaster19782,

:session is a symbol which Rails understands and treats differently than grabbing the session[:user_id] cookie's value.


What caused Rails to want to convert the symbol into an integer?
(Why the error: no implicit conversion of Symbol into Integer)


While you're waiting for Zeke to reply,

no implicit conversion of Symbol into Integer


@pymaster19782 find() defaults to find_by_id(), which takes an integer as a parameter. Since it wants an integer, it automatically assumes that will be what it's given, causing the error :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.