3

i want customize devise sign_up in order that after a json sign up post request, i get a json response.

So, in app/controllers i have created session_controller.rb:

class SessionsController < Devise::SessionsController

def create
   self.resource = warden.authenticate!(auth_options)
   set_flash_message(:notice, :signed_in) if is_navigational_format?
   sign_in(resource_name, resource)
   respond_to do |format|
       format.html do
        respond_with resource, :location => after_sign_in_path_for(resource)
       end
       format.json do
        render :json => { :response => 'ok'}.to_json, :status => :ok
       end
  end
 end
end

and in routes.rb:

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

Now i want make a json post request to sign up a user and get a json response. I set the URL: localhost:3000/users.json

Method: Post

Header: Content-Type: application/json

Data: {"user":{"email":"test@gmail.com", "password":"password123", "password_confirmation":"password123"}}

Why i don't receive the correct json response? I receive:

Staus:406 Not Acceptable

X-Runtime: 0.102006 Date: Tue, 02 Apr 2013 16:03:03 GMT Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16) Content-Type: application/json; charset=utf-8 Cache-Control: no-cache Connection: Keep-Alive Content-Length: 1 X-Request-Id: 24f5d66b1de09560b88e332e06b33c1b X-Ua-Compatible: IE=Edge

Tom
  • 4,007
  • 24
  • 69
  • 105

0 Answers0