Rubies on rails User registration using API call for API

Can someone tell me how to register a user from a mobile device (remainder API) in ruby ​​on rails. I am using Devise with Rails 3.0.

he gives me the following error

NameError in Devise :: CustomRegistrationsController # create

+4
source share
2 answers

I redefine the functionality of the development registration controller as follows.

def create respond_to do |format| format.html { super } format.json { build_resource if resource.save render :status => 200, :json => resource else render :json => resource.errors, :status => :unprocessable_entity end } end end 

this solved the problem and I added

  skip_before_filter :verify_authenticity_token, :only => :create 

to avoid authentication.

+10
source

Wouldn't it be easier to create presentations for mobile devices than creating applications on Android and iOS? If you need an API, send POST requests to / users / sign _up (and the like), for example, look at localhost: 3000 / users / sign_up and change the form action="/users.json" parameter to action="/users.json" , then click "Submit" and you will get an API response for me (for setting vanilla):

{"email":["has already been taken"],"password":["doesn't match confirmation","is too short (minimum is 6 characters)"]}

This way you can debug the API (which follows the standard conventions) with your browser. Note that on rails routes only the parameter is changed :format (you can choose .json or .xml for the API response)

POST information sent by my browser:

"utf8=βœ“&authenticity_token=n5vXMnlzrXefnKQEV4SmVM8cFdHDCUxMYWEBMHp9fDw%3D&user[email]=asd%40fasd.org&user[password]=321&user[password_confirmation]=1233&commit=Sign+up"

+1
source

Source: https://habr.com/ru/post/1388440/


All Articles