本文介绍了Devise + Rails-API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在从一个新的rails-api项目开始一个API。
我想使用Devise进行所有身份验证。我已经从我最近的谷歌搜索会议中学到了很多。我有一个工作的SessionsController,但是我注意到RegisterController,我当然错过了关于Rails-API + Devise的二重奏。

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>)`

从纯API的角度来看,我应该继续使用Devise Flash消息,因为我不想渲染视图?根据我将渲染JSON的原则,我没有包含 ActionDispatch :: Flash 。那么有没有办法妥善处理这种情况?

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?

谢谢。

推荐答案

我宁愿建议在json中发送消息,而不是发送flash [:messages]。如果你没有处理视图,那么去查看json,不需要flash。

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.

这样的东西:

      render :json => {:message => "message", :data => data}

这篇关于Devise + Rails-API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:33