LoginSignup
14
7

More than 3 years have passed since last update.

【Rails】devise_token_authを導入後、ユーザー登録しようとしたらcreateアクションがないと言われた

Last updated at Posted at 2019-12-29

はじめに

以下記事を参考にgem devise_token_authを導入し、Postmanで新規ユーザー登録しようとしたらエラーが発生したので解決法を残します。

(記事通りの手順に沿っていて、漏れがなければ発生しない内容です)

Rails 5 API + Vue.js + devise_token_authでTwitterと連携するSPAを作る(①RAILS編) - Qiita
※とても分かりやすい記事でした!ありがとうございます。

エラー内容(rails serverより抜粋)

AbstractController::ActionNotFound (The action 'create' could not be found for Api::V1::Auth::RegistrationsController):

環境

OS: macOS Catalina 10.15.1
Ruby: 2.6.5
Rails: 6.0.2.1

結論

クラスの継承漏れ。

解決法

$ rails g controller api/v1/auth/registrations

上記コマンドで自動生成された
registrations_controller.rb
の書き換え漏れが原因でした。

class Api::V1::Auth::RegistrationsController < ApplicationController

...

end

上:自動生成されたコントローラー

下:書き換え後のコントローラー

class Api::V1::Auth::RegistrationsController < DeviseTokenAuth::RegistrationsController

...

end

or

module Api
  module V1
    module Auth
      class RegistrationsController < DeviseTokenAuth::RegistrationsController

...
      end
    end
  end
end

おわりに

最後まで読んで頂きありがとうございました:bow_tone1:

しょうもないミスでしたが、どなたかの参考になれば幸いです:relaxed:

参考にさせて頂いたサイト(いつもありがとうございます)

14
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
7