LoginSignup
3
2

More than 3 years have passed since last update.

[Rails] Deviseのユーザー登録後失敗後のルーティングが/usersになる件の対処

Posted at

概要

現在運営しているカフェサークルのサイトをrailsで作成しているのですがdeviseの新規登録が失敗したときのルーティングがusers/sign_in > /users になってしまい、リロードした際にページが見つからないエラーが出ている状態でした。

解決策

deviseのscopeで/usersを新規登録のルーティングに設定してあげればよい。
具体的には以下のようにroutes.rbに設定を追加する。

routes.rb
  devise_scope :user do
    # TIPS: ユーザー登録しっぱいのリダイレクトのエラーを防ぐ https://github.com/heartcombo/devise/blob/master/app/controllers/devise/registrations_controller.rb
    get '/users', to: 'devise/registrations#new'
  end

これで、deviseが/usersを新規登録のルーティングと認識してエラーが起こらなくなる。

参考

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