getting devise to return json data when signing out

Hi all,

In curl (the command line program), I can successfully log a user in using devise:

def create     respond_to do |format|         format.json {           if user_signed_in?             return render :json => {:success => true, :errors => ["Already logged in."]}           end           resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")           return sign_in_and_redirect(resource_name, resource)         }      end    end

   def sign_in_and_redirect(resource_or_scope, resource=nil)        scope = Devise::Mapping.find_scope!(resource_or_scope)        resource ||= resource_or_scope        sign_in(scope, resource) unless warden.user(scope) == resource        return render :json => { :success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}    end

   def failure        return render :json => {:success => false, :errors => ["Login failed."]}    end

   def logged_in      return render :json => {:success => false, :errors => ["Already logged in."]}    end

However, once they are logged in, they are never logged out. So I want to be able to log out via curl and return json (curl is my testing devise right now, but ultimately I intend this to work through the iphone).

I add this to users/session controller:

def destroy      respond_to do |format|        format.json {          return sign_out_and_redirect(resource_or_scope)        }      end    end

   def sign_out_and_redirect(resource_or_scope)        scope = Devise::Mapping.find_scope!(resource_or_scope)        if Devise.sign_out_all_scopes          sign_out_all_scopes        else          sign_out(scope)        end        return render :json => {:status => :signed_out}      end

I get a "udefined method or variable resource_or_scope". The problem is if i define this sign_out_and_redirect method in the application controller, as another forum recommended:

it never gets called when I do: http://localhost:3000/users/sign_out.json. And no json data is ever returned.

And through curl, a strange thing happens with this:

curl -X POST http://localhost:3000/users/sign_out.json -d ''

it says no route for "users/sign_out", which is odd it says that, since users/sign_out gets invoked fine on html page.

thanks for response

I also asked this on stackoverflow:

I am finding it difficult to resolve this issue.