Ruby on Rails User Registration Using Rest API Call and Devise

User Registration in Devise through API

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

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

Ruby on rails User registration using rest API call and Devise

I've override the functionality of devise registration controller with the following.

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've added

    skip_before_filter :verify_authenticity_token, :only => :create

to avoid authenticity check.

Rails + Devise + API + User Registration

Devise already has all this setup. Based on your signup path, I infer that you mounted Devise onto http://localhost:3000/users. Devise includes all the controllers and views that are required, including the log in form, the sign up form, the email confirmation form and the password reset forms.

GET http://localhost:3000/users/sign_up is actually a form for users to signup at. The form on that page will POST to http://localhost:3000/users/, which goes to Devise's registration controller's create action.

Assuming there is no action/view already at /users/sign_up, the sign up form should be there, go check if it is there (assuming you set up devise_for correctly in your routes.rb file).

Rails devise app to create a REST api for mobile application

Add skip_before_filter :verify_authenticity_token to your API controller.
But true way for this case it's https://github.com/doorkeeper-gem/doorkeeper

how do you update a devise user via API calls

Well you can build your own actions in the devise controller

use this to generate the controllers for the users

rails generate devise:controllers users

the controllers will be created in app/controllers/users/

then you can add your own action to the controller

for example:

def update_info
@user = User.find(params[:id])
if @user.update(user_params)
puts 'the user info successfully updated' #add whatever you want
else
puts 'failed'
end
end

after that, you need to create a route for the action in the routes.rb

devise_scope :user do
put 'users/:id', to: 'users/sessions#update_info'
end


Related Topics



Leave a reply



Submit