前提・実現したいこと
deviseのコントローラにアクションを追加したい
試したこと
deviseのコントローラーをカスタマイズしています。
1.rails g devise:controllers users でdebiseのコントローラーを継承したコントローラーを生成
2.controllers/users/resistrations_controllerの中にsignuplistアクションを追加
3.routes.rbにdevise_scopeブロックでルートを追加
4.ブラウザからlocalhost:3000/users/signuplistにリクエスト
5.views/devise/registrations/signup_list.html.hamlに書いたビューの表示を確認
以上の手順で進めました。
最初はビューを確認できましたが、ユーザーを作成した後同じパスに行くと下記のようなエラーが出ました。
登録したユーザーをデータベースで削除してみましたが、同じエラーです。
#routes.rb Rails.application.routes.draw do root 'items#index' resources :items do resources :sold, only: [:index, :show] end devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions', passwords: 'users/passwords' } devise_scope :users do get 'users/signuplist' => 'users/registrations#signuplist' end resources :users, only: [:index, :show] do member do get 'identification' get 'register_card' get 'profile' get 'logout' end end end
#resistrations_controller.rb # frozen_string_literal: true class Users::RegistrationsController < Devise::RegistrationsController # before_action :configure_sign_up_params, only: [:create] # before_action :configure_account_update_params, only: [:update] def signuplist end # GET /resource/sign_up # def new # super # end # POST /resource # def create # super # end
#エラー Could not find devise mapping for path "/users/signuplist". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]
エラーを読むと、ルートがscopeブロックに入っていないとのことですが、正しくかけていると思います。
2)に関してはテスト環境での話だと思うので今回は当てはまらないかなと思いました。
初心者のためdeviseの理解もまだまだです。
回答よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/03/28 23:12