通过API在Devise中进行用户注册

编程入门 行业动态 更新时间:2024-10-08 22:12:24
本文介绍了通过API在Devise中进行用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近开始使用Rails 5开发REST API.我正在尝试通过API调用来执行用户粗略的操作.我已经为用户设置了一个基本的设计.

I have recently started developing REST APIs with rails 5. I am trying to do User crude actions through API calls. I have set up a basic devise for users.

在我的路线上,我有这个:

In my routes I have this:

Rails.application.routes.draw do devise_for :users, :controllers => {sessions: 'sessions', registrations: 'registrations'} end

我创建了两个单独的控制器session_controller和registrations_controller来覆盖devise方法并使其接受JSON格式.

I created two separate controllers sessions_controller and registrations_controller to override devise methods and make it accept JSON format.

class RegistrationsController < Devise::RegistrationsController respond_to :json end

class SessionsController < Devise::SessionsController respond_to :json end

我正在尝试注册一个传递以下数据的用户:

I am trying to register a user passing in the following data:

{ user: { email: me@gmail, password: password, password_confirmation: password } }

我的状态为200.但是在我的Rails服务器中,出现以下错误:

I get a status 200. but in my rails server I'm getting the following error:

Started POST "/users" for 23.233.9.94 at 2016-12-22 08:22:11 +0000 Processing by RegistrationsController#create as */* Parameters: {"Payload: { \r\n user: {\r\n email: me@gmail,\r\n password: password,\r\n password_confirmation: password\r\n }\r\n}"=>"[FILTERED]"} (0.2ms) begin transaction (0.1ms) rollback transaction Completed 200 OK in 5ms (Views: 0.2ms | ActiveRecord: 0.3ms)

所以我基本上有2个问题. 如何格式化JSON,以便我的设计控制器识别它并将其保存到数据库. 我的第二个问题是如何传递CSRF令牌.一个小例子真的可以帮到我. 提前致谢.

So I basically have 2 questions. How do I format the JSON so that my devise controllers recognize it and save it to the database. And my second question is how do I pass in a CSRF token. A little example would really help me out here. Thanks in advance.

推荐答案

您的JSON无效.您需要将字符串用双引号引起来

Your JSON is not valid.You need to enclose the string with double quotes

{ "user": { "email": "me@gmail", "password": "password", "password_confirmation": "password" } }

更多推荐

通过API在Devise中进行用户注册

本文发布于:2023-11-28 11:49:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户注册   API   Devise

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!