简体   繁体   English

借助RESTful登录

[英]RESTful login with devise

How do I do RESTful sign-up and sign-in using devise in Ruby on Rails (I am using version 4)? 如何在Ruby on Rails中使用devise进行RESTful注册和登录(我正在使用版本4)?

First of all, I could not find any documentation with regards to the parameters (eg email, password) that I should POST to the server. 首先,我找不到有关应张贴到服务器的参数(例如电子邮件,密码)的任何文档。

EDIT: Based on further investigation, it seems that RESTful login using json data (eg via AJAX) is not supported out of the box in the current version of devise. 编辑:基于进一步的调查,在当前版本的devise中,似乎不支持使用json数据(例如,通过AJAX)进行RESTful登录。 When I send a JSON request it responds with a HTML page instead of a JSON object. 当我发送JSON请求时,它会以HTML页面而不是JSON对象作为响应。 Does this mean that I need to create custom controller for handling user registration and login? 这是否意味着我需要创建用于处理用户注册和登录的自定义控制器? If so, please elaborate. 如果是这样,请详细说明。

Most things are the same. 大多数事情都是一样的。 The main change is the switch to strong parameters. 主要变化是切换到强参数。 To add your own strong parameters, put this in your application controller: 要添加自己的强参数,请将其放在应用程序控制器中:

def configure_devise_params
    devise_parameter_sanitizer.for(:sign_up) do |u|
        u.permit(fields go here)
    end
end 

Otherwise, its essentially the same procedure as in 3. If there is something else you don't know how to do, please ask a more specific question. 否则,其步骤与3中的步骤基本相同。如果还有其他您不知道该怎么做的步骤,请提出一个更具体的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM