devise_token_auth undefined method 'create_token' issue












1















In my rails 5 application I have used "devise_token_auth" gem for developing token based API's for authentication purpose. Till date everything was working good, but suddenly I am getting below error,



NoMethodError (undefined method `create_token' for #<User:0x00000002268570>


Could not find any solution on google. Below is the full error,



Started POST "/api/v1/auth/sign_in" for ::1 at 2018-06-05 16:32:34 +0530
(28.8ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
(11.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
Processing by DeviseTokenAuth::SessionsController#create as */*
Parameters: {"email"=>"admin@example.com", "password"=>"[FILTERED]", "session"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]"}}
Unpermitted parameter: :session
Unpermitted parameter: :session
User Load (12.3ms) SELECT `users`.* FROM `users` WHERE (BINARY email = 'admin@example.com' AND provider='email') ORDER BY `users`.`id` ASC LIMIT 1
Unpermitted parameter: :session
Unpermitted parameter: :session
Completed 500 Internal Server Error in 395ms (ActiveRecord: 92.9ms)

NoMethodError (undefined method `create_token' for #<User:0x00000002268570>
Did you mean? created_at):









share|improve this question



























    1















    In my rails 5 application I have used "devise_token_auth" gem for developing token based API's for authentication purpose. Till date everything was working good, but suddenly I am getting below error,



    NoMethodError (undefined method `create_token' for #<User:0x00000002268570>


    Could not find any solution on google. Below is the full error,



    Started POST "/api/v1/auth/sign_in" for ::1 at 2018-06-05 16:32:34 +0530
    (28.8ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
    (11.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
    Processing by DeviseTokenAuth::SessionsController#create as */*
    Parameters: {"email"=>"admin@example.com", "password"=>"[FILTERED]", "session"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]"}}
    Unpermitted parameter: :session
    Unpermitted parameter: :session
    User Load (12.3ms) SELECT `users`.* FROM `users` WHERE (BINARY email = 'admin@example.com' AND provider='email') ORDER BY `users`.`id` ASC LIMIT 1
    Unpermitted parameter: :session
    Unpermitted parameter: :session
    Completed 500 Internal Server Error in 395ms (ActiveRecord: 92.9ms)

    NoMethodError (undefined method `create_token' for #<User:0x00000002268570>
    Did you mean? created_at):









    share|improve this question

























      1












      1








      1








      In my rails 5 application I have used "devise_token_auth" gem for developing token based API's for authentication purpose. Till date everything was working good, but suddenly I am getting below error,



      NoMethodError (undefined method `create_token' for #<User:0x00000002268570>


      Could not find any solution on google. Below is the full error,



      Started POST "/api/v1/auth/sign_in" for ::1 at 2018-06-05 16:32:34 +0530
      (28.8ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
      (11.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
      Processing by DeviseTokenAuth::SessionsController#create as */*
      Parameters: {"email"=>"admin@example.com", "password"=>"[FILTERED]", "session"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]"}}
      Unpermitted parameter: :session
      Unpermitted parameter: :session
      User Load (12.3ms) SELECT `users`.* FROM `users` WHERE (BINARY email = 'admin@example.com' AND provider='email') ORDER BY `users`.`id` ASC LIMIT 1
      Unpermitted parameter: :session
      Unpermitted parameter: :session
      Completed 500 Internal Server Error in 395ms (ActiveRecord: 92.9ms)

      NoMethodError (undefined method `create_token' for #<User:0x00000002268570>
      Did you mean? created_at):









      share|improve this question














      In my rails 5 application I have used "devise_token_auth" gem for developing token based API's for authentication purpose. Till date everything was working good, but suddenly I am getting below error,



      NoMethodError (undefined method `create_token' for #<User:0x00000002268570>


      Could not find any solution on google. Below is the full error,



      Started POST "/api/v1/auth/sign_in" for ::1 at 2018-06-05 16:32:34 +0530
      (28.8ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
      (11.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
      Processing by DeviseTokenAuth::SessionsController#create as */*
      Parameters: {"email"=>"admin@example.com", "password"=>"[FILTERED]", "session"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]"}}
      Unpermitted parameter: :session
      Unpermitted parameter: :session
      User Load (12.3ms) SELECT `users`.* FROM `users` WHERE (BINARY email = 'admin@example.com' AND provider='email') ORDER BY `users`.`id` ASC LIMIT 1
      Unpermitted parameter: :session
      Unpermitted parameter: :session
      Completed 500 Internal Server Error in 395ms (ActiveRecord: 92.9ms)

      NoMethodError (undefined method `create_token' for #<User:0x00000002268570>
      Did you mean? created_at):






      ruby-on-rails-5 devise-token-auth






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 5 '18 at 11:08









      Hemant PatilHemant Patil

      9611




      9611
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I solved this error by using the Excluding Modules section of the docs.



          # app/models/user.rb
          class User < ActiveRecord::Base

          # notice this comes BEFORE the include statement below
          # also notice that :confirmable is not included in this block
          devise :database_authenticatable, :recoverable,
          :trackable, :validatable, :registerable,
          :omniauthable

          # note that this include statement comes AFTER the devise block above
          include DeviseTokenAuth::Concerns::User
          end


          Including the DeviseTokenAuth::Concerns::User was what solved the undefined method problem, but I needed this section because it required confirmation (I put the include before the devise block)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50698593%2fdevise-token-auth-undefined-method-create-token-issue%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I solved this error by using the Excluding Modules section of the docs.



            # app/models/user.rb
            class User < ActiveRecord::Base

            # notice this comes BEFORE the include statement below
            # also notice that :confirmable is not included in this block
            devise :database_authenticatable, :recoverable,
            :trackable, :validatable, :registerable,
            :omniauthable

            # note that this include statement comes AFTER the devise block above
            include DeviseTokenAuth::Concerns::User
            end


            Including the DeviseTokenAuth::Concerns::User was what solved the undefined method problem, but I needed this section because it required confirmation (I put the include before the devise block)






            share|improve this answer




























              0














              I solved this error by using the Excluding Modules section of the docs.



              # app/models/user.rb
              class User < ActiveRecord::Base

              # notice this comes BEFORE the include statement below
              # also notice that :confirmable is not included in this block
              devise :database_authenticatable, :recoverable,
              :trackable, :validatable, :registerable,
              :omniauthable

              # note that this include statement comes AFTER the devise block above
              include DeviseTokenAuth::Concerns::User
              end


              Including the DeviseTokenAuth::Concerns::User was what solved the undefined method problem, but I needed this section because it required confirmation (I put the include before the devise block)






              share|improve this answer


























                0












                0








                0







                I solved this error by using the Excluding Modules section of the docs.



                # app/models/user.rb
                class User < ActiveRecord::Base

                # notice this comes BEFORE the include statement below
                # also notice that :confirmable is not included in this block
                devise :database_authenticatable, :recoverable,
                :trackable, :validatable, :registerable,
                :omniauthable

                # note that this include statement comes AFTER the devise block above
                include DeviseTokenAuth::Concerns::User
                end


                Including the DeviseTokenAuth::Concerns::User was what solved the undefined method problem, but I needed this section because it required confirmation (I put the include before the devise block)






                share|improve this answer













                I solved this error by using the Excluding Modules section of the docs.



                # app/models/user.rb
                class User < ActiveRecord::Base

                # notice this comes BEFORE the include statement below
                # also notice that :confirmable is not included in this block
                devise :database_authenticatable, :recoverable,
                :trackable, :validatable, :registerable,
                :omniauthable

                # note that this include statement comes AFTER the devise block above
                include DeviseTokenAuth::Concerns::User
                end


                Including the DeviseTokenAuth::Concerns::User was what solved the undefined method problem, but I needed this section because it required confirmation (I put the include before the devise block)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 3:13









                Adam DAdam D

                17929




                17929






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50698593%2fdevise-token-auth-undefined-method-create-token-issue%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Homophylophilia

                    Updating UILabel text programmatically using a function

                    Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage