I set up a rails 3.2.11 application using Devise for authentication.
I want to use ember.js as an mvc framework.
When I launch an ajax call to the POST /users.json route I get a 406 Not Acceptable.
Here is my ajax call :
urlBase : '/users'
signup : (username, email, password, passwordConfirmation) ->
$.ajax
url: "#{@.get('urlBase')}.json"
type: "POST"
dataType: "json"
data:
"user[username]": username
"user[email]": email
"user[password]": password
"user[password_confirmation]": passwordConfirmation
success: (data) ->
alert('Completed sign up process: '+ JSON.stringify(data));
@errorMsg = "Signed up successfully."
error: (jqXHR, textStatus, errorThrown) ->
alert "Error completing sign up: " + textStatus + " error: " + errorThrown
Here are the logs :
Started POST "/users.json" for 127.0.0.1 at 2013-01-14 14:38:57 +0100
Processing by Devise::RegistrationsController#create as JSON
Parameters: {"user"=>{"username"=>"obo", "email"=>"obo@obo.dv", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
(1.3ms) begin transaction
User Exists (1.3ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'obo@obo.dv' LIMIT 1
(0.1ms) rollback transaction
Completed 406 Not Acceptable in 311ms (ActiveRecord: 2.6ms)
I do not understand why this happens.
Zajn’s answer explains that DeviseController now responds only to HTML format (since version 2.2.0).
The changelog say to add the JSON format to the DeviseController.respond_to.
I did it subclassing SessionsController and RegistrationsController and adding respond_to :json :