Devise: Default/preffered way to teach Devise to respond to JSON?

Created on 19 Feb 2015  路  6Comments  路  Source: heartcombo/devise

Hi,

I had an issue with my angular + rails app, where after upgrading to rails 4.2 Devise stopped responding to JSON.

After some research/debugging I have fixed that by adding

config.navigational_formats = ['*/*', :html, :json]

in initializers/devise.rb

However, I have seen many blog posts / SO answers and none mentions this approach. People recommend vairous things such as:

config.to_prepare do
  DeviseController.respond_to :html, :json
end

or

class RegistrationsController < Devise::RegistrationsController  
    respond_to :json
end  

and the like.

Questions:

  1. What is the preffered way to teach Devise to respond to JSON?
  2. Do you think it's a good idea to add this to the readme (it's quite popular these days). If yes I could sign up to contribute it.

Most helpful comment

this blogpost worked for me.

All 6 comments

Your code is not teaching Devise how to handle JSON. In fact, it is sending
the wrong information because JSON is not a navigational format.

_Jos茅 Valim_
www.plataformatec.com.br
Skype: jv.ptec
Founder and Lead Developer

The two mentioned solutions are fine, but you can simply call respond_to in your application controller. In any case, please use the mailing list or StackOverflow for questions/help, where a wider community will be able to help you. We reserve the issues tracker for issues only.

Yep, I realized my mistake shortly after. Thanks anyways!

What is the solution, facing the same issue...

this blogpost worked for me.

@bikezilla This blog works for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ragesoss picture ragesoss  路  3Comments

jmarchello picture jmarchello  路  4Comments

Pedroknoll picture Pedroknoll  路  3Comments

emn178 picture emn178  路  4Comments

afuno picture afuno  路  3Comments