質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

924閲覧

2段階認証のNo route matchesを解決したい

newbie8

総合スコア0

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2022/01/10 07:49

編集2022/01/13 04:22

前提・実現したいこと

ttps://www.autovice.jp/articles/171#part-f25eff337beca913
こちらのサイトを参考にrotpを使った2段階認証の実装を勉強しているのですが、

NameError in TwoStepVerifications#new
Showing C:/Users/user/rails/login_app/app/views/two_step_verifications/new.html.erb
Did you mean? @otp_secret

が出て、QRコードの画面がでません。該当する箇所を変更(otp_secret_path → @otp_secret)したのち、QRコードは表示できるようになったのですが、認証しようとすると

No route matches [POST] "/two_step_verifications/ランダムな文字列"

と出て上手く認証できません。

当方、まったくの初心者で稚拙なところも多々あると思いますが、よろしければお力添えをお願いします。

発生している問題・エラーメッセージ

NameError in TwoStepVerification#new Showing C:/Users/user/rails/login_app/app/views/two_step_verification/new.html.erb where line #3 raised: undefined local variable or method `otp_secrets_path' for #<ActionView::Base:0x00000000006c60> Did you mean? @otp_secret
No route matches [POST] "/two_step_verification/EM7ADJLIUK2SZ3PL6Q4NQ2KYKM3M6C4J" Rails.root: C:/Users/user/rails/login_app Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom

該当のソースコード

rails

1 2#login_app\app\views\two_step_verifications\new.html.erb 3 4<h2>2-Step Verification</h2> 5 6#以下赤文字 7<%= form_tag otp_secret_path, method: :post do %> 8 <%= hidden_field_tag :otp_secret, @otp_secret %> 9 10 <div class='field'> 11 <%= image_tag @qr_code %> 12 </div> 13 14 <div class='field'> 15 <%= label_tag :otp_attempt, 'Verify' %> <i>(enter a one-time password)</i><br /> 16 <%= text_field_tag :otp_attempt %> 17 </div> 18 19 <div class='actions'> 20 <%= submit_tag 'Verify' %> 21 </div> 22<% end %>

該当のソースコード

rails

1#login_app\config\routes.rb 2 3Rails.application.routes.draw do 4 resources :two_step_verification, only: [:new, :create] 5 6 get 'two_step_verifications/new' 7 get 'two_step_verifications/create' 8 devise_for :users 9 root to:'comments#index' 10 get 'comments/index' 11 # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 12end 13

試したこと

該当する箇所を変更(otp_secret_path → @otp_secret)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2022/01/10 09:06 編集

エラーメッセージは編集しないで全部のせてください
guest

回答1

0

resources :two_step_verification, only: [:new, :create]
なので、postへのrouteが無いです。

修正
resources :two_step_verification, only: [:new, :create]
であって、
resources :two_step_verifications, only: [:new, :create]
でないからですね。

投稿2022/01/10 09:08

編集2022/01/14 00:46
winterboum

総合スコア23347

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問