Ezequiel Ramiro
Ezequiel Ramiro

Reputation: 760

Devise - how to 'after confirmation path' return json respond.

I have an API made with RUBY using Devise to handle authentication.

Also I'm using :confirmable property but I'm having some trouble to get a respond.

I'm doing a GET request, sending the validate token to devise/confirmations#show, which works fine because after that I try to get into my app and I can. The thing is, when I send that request, I'm getting a respond error cause I don't have any redirect route cause I'm not using any views (is an API)

I try to create a new class from devise:

class ConfirmUserController < Devise::ConfirmationsController

private
  def after_confirmation_path_for(resource_name, resource)
    respond_to do |format|
      format.json { render json: {msg: 'success'} }
    end
  end
end

Basically what I need is when a user confirms their account, the api should send a 'success' message to my app. I don't want to redirec to another view.

How can I do that?

Upvotes: 1

Views: 777

Answers (1)

gwcodes
gwcodes

Reputation: 5690

Having a look at the source should explain why this doesn't work. Your respond_to block is in the wrong place and therefore not having any effect.

You are overriding after_confirmation_path_for which should return a path, but respond_with_navigational in #show is a parameter of redirect_to, which will redirect regardless of what is returned.

Since you already have a custom controller, I suggest that you override the #show action too, and respond with JSON directly from there.

Upvotes: 1

Related Questions