Devise + Rails-API

我怕爱的太早我们不能终老 提交于 2019-12-10 15:59:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!