LoginSignup
2
1

More than 3 years have passed since last update.

Unknown action

Last updated at Posted at 2020-03-22

Unknown action

railsでアプリを作成していたところ、初めて見るエラーが発生しました。
結果からいうとコードの誤記という恥ずかしいイージーミスでしたので、反省と忘れないために書きたいと思います。

エラー発生

Users::RegistrationsControllerのnew_credit_cardアクションを実行したところ以下のエラーが発生しました。

Unknown action
The action 'new_creditcard' could not be found for Users::RegistrationsController

なるほど、アクションがないのか。
ということで、RegistrationsControllerを確認します。

解決

以下がコントローラーで当該のアクションを呼び出してる箇所とroutes.rbです。

uses/registrations_controller.rb
render :new_credit_card
config/routes.rb
get 'creditcards', to: 'users/registrations#new_creditcard'

しっかりアクション名を書き間違えていました。
ということで、これを修正することでエラーが直りました。

おわり

今回はアクション名がルーティングとコントローラーで不一致だったためエラーが起きましたが、呼び出したいアクションをコントローラーのprivate以下に書いた場合でも、今回と同じエラーが起きるそうです。
最後まで見ていただきありがとうございました。

2
1
0

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
2
1