问题
So, I'm starting an API from a new rails-api project. I would like to use Devise for all the authentication stuff. I already learned a lot from my recent googling-sessions. I have a working SessionsController, however I noticed with the RegisterController that I certainly missed something about the duo Rails-API+Devise.
I still get the following error :
NameError (undefined local variable or method 'flash' for # <RegistrationsController:0x007ff6022b44b8>)`
From a pure API perspective should I keep working with Devise flash messages since I don't want to render views? I didn't included ActionDispatch::Flash
based on the principe that I'll just render JSON. So, is there a way to properly deal with that case?
Thank you.
回答1:
I would rather suggest to send messages in json instead of having flash[:messages]. If you are not dealing with views then go for json, flash is not required.
Something like:
render :json => {:message => "message", :data => data}
来源:https://stackoverflow.com/questions/17292137/devise-rails-api