0

I am using annotate in my app and all models are successfully annotated except for user.rb, which shows the following error when I annotate:

Unable to annotate user.rb: wrong number of arguments (0 for 1)

Outside of annotating, everything else works fine. User creation, updating, deletion, login, sign out, it all works properly. I have determined that the problem is with the Digest::SHA1, which I use to create session tokens, as demonstrated below in the snippet from user.rb.

def User.new_remember_token
  SecureRandom.urlsafe_base64
end

def User.hash(token)
  Digest::SHA1.hexdigest(token.to_s)
end

private

  def create_remember_token
    remember_token = User.hash(User.new_remember_token)
  end

If I remove the second (def User.hash(token)) and instead do the following:

def User.new_remember_token
  SecureRandom.urlsafe_base64
end

private
  def create_remember_token
    remember_token = Digest::SHA1.hexdigest(User.new_remember_token.to_s)
  end

then annotate is happy and successfully annotates user.rb. However, this isn't really the ruby way as my session helper utilizes that User.hash(token) call several times. What am I not understanding about Digest::SHA1.hexdigest or the way that I am utilizing it?

Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
topher
  • 301
  • 1
  • 5
  • 14

1 Answers1

0

Looks like you're working through The Rails Tutorial.

The likely reason you're seeing issues with your User.hash method is nothing to do with Digest::SHA1, but is because the method itself is inadvertently overriding Ruby's Object#hash method, which is giving you some cryptic errors. Link to Github issue about it.

So, like this commit to the Sample App repository, rename all your instances of User.hash to User.digest and hopefully that should fix your errors.

Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122