Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why should I use .to_json to get the right json object and not an array? #400

Closed
AdamQuadmon opened this issue Oct 6, 2015 · 1 comment

Comments

@AdamQuadmon
Copy link

In order to have the correct response I need to add .to_json to render calls (render json: {}.to_json)

What's wrong with me?

#My routes
mount_devise_token_auth_for 'User', at: 'api/auth', controllers: {
      token_validations:  'overrides/token_validations'
  }

# token_validations

module Overrides
  class TokenValidationsController < DeviseTokenAuth::TokenValidationsController
    skip_before_filter :assert_is_devise_resource!, :only => [:validate_token]
    before_filter :set_user_by_token, :only => [:validate_token]

    def validate_token
      # @resource will have been set by set_user_token concern
      if @resource
        yield if block_given?
        render :json => {
                   :success => true,
                   :data => @resource.token_validation_response
               }.to_json
      else
        render json: {
                   success: false,
                   errors: [I18n.t("devise_token_auth.token_validations.invalid")]
               }.to_json, status: 401
      end
    end
  end
end
@zachfeldman
Copy link
Contributor

Hi there @AdamQuadmon ,

In an effort to cleanup this project and prioritize a bit, we're marking issues that haven't had any activity in a while with a "close-in-7-days" label. If we don't hear from you in about a week, we'll be closing this issue. Obviously feel free to re-open it at any time if it's the right time or this was done in error!

If you are still having the issue (especially if it's a bug report) please refer to our new Issue Template to provide some more details to help us solve it.

Hope all is well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants