前提・実現したいこと
devise で新規登録ごの遷移先を変更したいです。
二つのログイン機能をdeviseで実装しています。
片方(user_devises)はうまく指定した通り、遷移してくれるのですが、もう片方(companies)で同じように、指定してもうまくいかず、rootに遷移してしまします。
両方とも指定した通り、遷移するようにしたいです。
該当のソースコード
app/controllers/companies/registrations_controller.rb
ruby
1# frozen_string_literal: true 2 3class Companies::RegistrationsController < Devise::RegistrationsController 4 # before_action :configure_sign_up_params, only: [:create] 5 # before_action :configure_account_update_params, only: [:update] 6 7 # GET /resource/sign_up 8 # def new 9 # super 10 # end 11 12 # POST /resource 13 # def create 14 # super 15 # end 16 17 # GET /resource/edit 18 # def edit 19 # super 20 # end 21 22 # PUT /resource 23 # def update 24 # super 25 # end 26 27 # DELETE /resource 28 # def destroy 29 # super 30 # end 31 32 # GET /resource/cancel 33 # Forces the session data which is usually expired after sign 34 # in to be expired now. This is useful if the user wants to 35 # cancel oauth signing in/up in the middle of the process, 36 # removing all OAuth session data. 37 # def cancel 38 # super 39 # end 40 41 # protected 42 43 # If you have extra params to permit, append them to the sanitizer. 44 # def configure_sign_up_params 45 # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) 46 # end 47 48 # If you have extra params to permit, append them to the sanitizer. 49 # def configure_account_update_params 50 # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 51 # end 52 53 #アカウント登録後のリダイレクト先 54 def after_sign_up_path_for(resource) 55 new_company_registration_path 56 end 57 58 # The path used after sign up for inactive accounts. 59 def after_inactive_sign_up_path_for(resource) 60 new_company_registration_path 61 end 62end
app/controllers/user_devises/registrations_controller.rb
ruby
1# frozen_string_literal: true 2 3class UserDevises::RegistrationsController < Devise::RegistrationsController 4 # before_action :configure_sign_up_params, only: [:create] 5 # before_action :configure_account_update_params, only: [:update] 6 7 # GET /resource/sign_up 8 # def new 9 # super 10 # end 11 12 # POST /resource 13 # def create 14 # super 15 # end 16 17 # GET /resource/edit 18 # def edit 19 # super 20 # end 21 22 # PUT /resource 23 # def update 24 # super 25 # end 26 27 # DELETE /resource 28 # def destroy 29 # super 30 # end 31 32 # GET /resource/cancel 33 # Forces the session data which is usually expired after sign 34 # in to be expired now. This is useful if the user wants to 35 # cancel oauth signing in/up in the middle of the process, 36 # removing all OAuth session data. 37 # def cancel 38 # super 39 # end 40 41 # protected 42 43 # If you have extra params to permit, append them to the sanitizer. 44 # def configure_sign_up_params 45 # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) 46 # end 47 48 # If you have extra params to permit, append them to the sanitizer. 49 # def configure_account_update_params 50 # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 51 # end 52 53 #アカウント登録後のリダイレクト先 54 def after_sign_up_path_for(resource) 55 new_user_devise_session_path 56 end 57 58 #アカウント情報、プロフィール編集後のリダイレクト先 59 def after_update_path_for(resource) 60 # マイページへ遷移 61 user_devise_path(resource.id) 62 end 63 64 # The path used after sign up for inactive accounts. 65 def after_inactive_sign_up_path_for(resource) 66 new_user_devise_session_path 67 end 68end 69
app/views/devise/registrations/new.html.erb
erb
1<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 2 <%= render "devise/shared/error_messages", resource: resource %> 3 4 <div class="p-register__field"> 5 <%= f.label :メールアドレス %><br /> 6 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 7 </div> 8 9 <div class="p-register__field"> 10 <%= f.label :パスワード %> 11 <% if @minimum_password_length %> 12 <em>(<%= @minimum_password_length %>文字以上)</em> 13 <% end %><br /> 14 <%= f.password_field :password, autocomplete: "new-password" %> 15 </div> 16 17 <div class="p-register__field"> 18 <%= f.label :パスワード確認 %><br /> 19 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 20 </div> 21 22 23 <div class="p-register__actions"> 24 <p><a href="">利用規約</a>に同意して</p> 25 <%= f.submit "登録する", class: "c-btn__register u-mtb20" %> 26 <p>すでに登録されている方は<a href="/user_devises/sign_in">こちら</a></p> 27 28 </div> 29 <% end %>
補足情報(FW/ツールのバージョンなど)
Rails 5.1.6
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。