Ember.js with application for rails: 406 Not allowed at registration

I installed the rails 3.2.11 application using Devise for authentication. I want to use ember.js as the mvc framework.

When I run an ajax call on the POST / users.json route, I get 406 invalid.

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 is happening.

+4
source share
2 answers

Zajn's answer explains that DeviseController now only responds to the HTML format (since version 2.2.0). changelog is said to add the JSON format to DeviseController.respond_to.

I made this subclassic of SessionController and RegistrationsController and added reply_to: json:

 class RegistrationsController < Devise::RegistrationsController respond_to :json end class SessionsController < Devise::RegistrationsController respond_to :json end 
+2
source

What version of Devise are you using?

I ran into a similar problem last week after accidentally updating to version 2.2.0. Some incompatible changes have been made in this version, including a change that, by default, DeviseController only responded to HTML . You can add additional formats such as JSON , although this should solve your problem.

Read about the changes in Devise in their changelog on Github . If you do not want this, try downgrading to Devise 2.1.2, which I did at the moment.

+4
source

All Articles