mardi 6 juillet 2021

how can I see the attributes of my object

I've got this line in my code

test = User.first

which gives me back

#<User:0x270e37c>

I know I have attributes on this object like "id" and "login"...when I run the debugger in my ide I can see "@attributes = Hash(17 elements)" and I can see them listed inside as 'id' = "433" and 'login' = "firstname.lastname" etc

@attributes = Hash(17 elements)
'id' = "433"
'login' = "firstname.lastname"
...

How do I return the value of 'id'?

test.attribute.id? <--- gives an error

I know this is simple but I just do not remember. Thanks for you time

UPDATE:

test.attributes["id"] is not the answer. it gives the error...

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map

Aucun commentaire:

Enregistrer un commentaire