Is the existence of 'current_user' mandatory?
I'm creating a Rails app from scratch and still don't have any authentication mechanism in place.
I had to specify a current_user method in the controller in order to produce json from the active_model_serializer, otherwise i get an exception:
NoMethodError in EntriesController#index
undefined method `current_user' for #EntriesController:0x007fc14cb4a8d8
Yes, it is mandatory. IF you don't have a current_user, you may as well return nil for now.
Thanks for the update, how would you deal with multiple user resources. Example, having current_user and current_admin depending on the controller.
Is this possible as of today? If no, is it meant to move toward this path?
current_user would have to change based on what is signed in, the admin or the current user. If I am not wrong, there is a way to tell active model serializers to use another method, like current_serialization_scope, take a look at the source.
thanks for the tip, I'll dig the source for more then. Thanks a lot for your awesome work.
current_user is not mandatory anymore as of https://github.com/josevalim/active_model_serializers/commit/d5d917ea5687e313069c5b53050c470e236f3184
See https://github.com/josevalim/active_model_serializers/blob/d5d917ea5687e313069c5b53050c470e236f3184/lib/action_controller/serialization.rb#L12 for more details and how to use serialization_scope, it can be current_user or anything you like.