unable to sign up with json devise unable to sign up with json devise curl curl

unable to sign up with json devise


Here's what we use (check it at http://firststopcosmeticshop.co.uk -- "register" @ top)

 class RegistrationsController < DeviseController  prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]  prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]  before_filter :configure_permitted_parameters  prepend_view_path 'app/views/devise'  # GET /resource/sign_up  def new    build_resource({})    respond_with self.resource  end  # POST /resource  def create    build_resource(sign_up_params)    if resource.save      if resource.active_for_authentication?        set_flash_message :notice, :signed_up if is_navigational_format?        sign_up(resource_name, resource)        respond_with resource, :location => after_sign_up_path_for(resource)      else        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?        expire_session_data_after_sign_in!        respond_with resource, :location => after_inactive_sign_up_path_for(resource)      end    else      clean_up_passwords resource      respond_to do |format|        format.json { render :json => resource.errors, :status => :unprocessable_entity }        format.html { respond_with resource }      end    end  end  ....

Paths

I think your error is from your devise paths (trying to send a POST request to /sign_up). You can see the method should be create here:

sign_up (Devise::RegistrationsController#create) - Permits authentication keys plus password and password_confirmation

Why don't you try this in your config/routes.rb file:

devise_for :users, controllers: { sessions: "sessions", registrations: "registrations"}, path_names: { sign_in: 'sign_in', password: 'forgot', confirmation: 'confirm', unlock: 'unblock', sign_up: 'sign_up', sign_out: 'logout'}


If we run rake routes we can see that devise sign up (registration) has [new, create, update, ..]

cancel_user_registration GET    /users/cancel(.:format)                 devise/registrations#cancel   new_user_registration GET    /users/sign_up(.:format)                devise/registrations#new  edit_user_registration GET    /users/edit(.:format)                   devise/registrations#edit       user_registration PATCH  /users(.:format)                        devise/registrations#update                         PUT    /users(.:format)                        devise/registrations#update                         DELETE /users(.:format)                        devise/registrations#destroy                         POST   /users(.:format)                        devise/registrations#create

So, the route #new shows only the sign up page and to register new user we use #create and it's correct route: /users.json not /user/sign_up.json

As we can see here:

POST   /users(.:format)                        devise/registrations#create

Here's sign_up page inspect on browser, we can see action = "/users"

routes of devise registration


try these code ,I do it with my rails api

 devise_scope :user do    post 'users' => 'registrations#create', :as => 'user_registration'  end curl: //your-domain:3000/users --data "email=jump@gmail.com&password=123456789&password_confirmation=123456789"