ruby on rails - unable to sign up with json devise -


i have problem devise registration using /users/sign_up. have pass registration details via rails terminal using curl this:

curl: //your-domain:3000/users/sign_up --data "email=jump@gmail.com&password=123456789&password_confirmation=123456789" 

and should return:

{"success":true,"info":"registered","email":"jump@example.com","auth_token":"n8n5mpqfnddz3g1jrsc9"} 

but getting below error message:

actioncontroller::routingerror (no route matches [post] "/users/sign_up"): 

while users/sign_in working perfectly:

curl: //your-domain:3000/users/sign_in.json --data "email=abc@gmail.com&password=123456789" 

return:

{"success":true,"info":"logged in","auth_token":"czzbpins7mkkqjabhymo","email":"abc@gmail.com"} 

below registrationscontroller class:

class registrationscontroller < devise::registrationscontroller  before_filter :authenticate_user!, :except => [:create], :if => proc.new { |c| c.request.format == 'application/json' }   respond_to :json    prepend_view_path 'app/views/devise'    def create     build_resource     if resource.save       sign_in resource       resource.ensure_authentication_token!       render :status => 200,              :json => { :success => true,                         :info => "registered",                         :email => resource.email,                         :auth_token => resource.authentication_token }     else       render :status => :unprocessable_entity,              :json => { :`enter code here`success => false,                         :info => resource.errors }     end   end  end 

and routes.rb: has following settings:

 devise_for(:users, :controllers => { :sessions => "sessions", :registrations => 'registrations' }) 

here's use (check @ 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'    # /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 |format|         format.json { render :json => resource.errors, :status => :unprocessable_entity }         format.html { respond_with resource }       end     end   end   .... 

paths

i think error devise paths (trying send post request /sign_up). can see the method should create here:

sign_up (devise::registrationscontroller#create) - permits authentication keys plus password , password_confirmation

why don't try in 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'} 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -