1
votes

After setup a simple token check on the session rails spits out this

TypeError (no implicit conversion of Symbol into Integer)

app/controllers/sessions_controller.rb:21:in `verify_token'

on this method

so, as i checked seems right.

someone has any idea why this is happening on this method?

def verify_token
    @current_user = User.find_by(auth_token: request.headers['token'] [:auth_token])    
    if @current_user    
      render json: {message:"verified",  status: 200}    
    else    
      render_unauthorized("Token failed verification")
    end
end
1
Most probably request.headers['token'] returns an array, and you're trying to access an auth_token key, hence Ruby tries a conversion from the symbol to the array index. - Sebastian Palma
ahh ok, thank you Sebastian - user9157191

1 Answers

1
votes

The problem is `request.headers['token'] likely contains a string.

When you do

request.headers['token'] [:auth_token]

You are running the [] method on the string, which method is allowed if it contains an integer.

'carrot'[2]
=> 'r'

But it's not allowed if you use a symbol instead, as it can't automatically convert a symbol into an integer (no implicit conversion)

Probably would be sufficient to do...

@current_user = User.find_by(auth_token: request.headers['token'])