Rails: NameError (uninitialized constant UserSerializer) error message
How to solve fast_jsonapi serializer error?
Table of contents
Introduction
The fast_jsonapi
is a a lightning fast JSON:API serializer for Ruby Objects. Its github page can be accessed here.
The project is no longer maintained, but you might end up using it in some applications.
Issue
This is the usual error message:
NameError (uninitialized constant UserSerializer)
Tests
None of the following tests worked:
- Leave terminal and open it again;
- Open a new tab;
- Open the terminal on VS Code;
- Open the terminal on Linux console;
Reload!
Rails console;
Solution
For me, it worked to stop spring, which is a Rails application preloader.
- Exit Rails console
exit
- Stop the
spring
Rails application preloader
By the way, you can see all the available spring commands by usingspring stop
help
spring help
- Enter
Rails console
again
orrails c
rails console
- Run the test command
Here, I tried:
UserSerializer.new( User.first ).serializable_hash
or just type
UserSerializer
It'll return the class itself
spring
is still working
In case you're aspring
freak (Just kidding lol),spring
is fine.
Leave the terminal
exit
and there you go, spring
is fine
spring status
Conclusion
That's all. Hope you guys liked it. Let me know if you need any help.