環境:
ruby 2.6.5
Rails 6.0.0
devise 4.7.3 from https://github.com/heartcombo/devise.git (at ca-omniauth-2@e16d60d)
letter_opener
解決したいこと:
letter_openerから開いた、deviseのconfirmation_instructionsメールにある認証URLから
ユーザー認証をさせたい。
状況:
上記操作をすると、認証URLから飛んだらrouting errorがおきます。
url:
https://company.localhost:3001/companies/confirmation?confirmation_token=QhUcNyibR7sJrVRs61-F
しかし、routesを確認すると存在しています。
サブドメインでないroutesのユーザーは、deviseのメール内の認証URLから認証できました。
原因がわからず困っています。ここからどう調べたら良いのかも。。
※rails6 に deviseで、3モデルを分けて管理しています。
※サブドメインが原因かと思っていますが核心にたどり着けません。
※サブドメインは、hostsとrailsでも設定していてアクセスすることはできます。
どんな些細な情報でも良いのでお聞かせいただければと思います。
よろしくお願い致します。
追記ーーーーーーーーーーーー
OKなURL:
https://localhost:3001/users/confirmation?confirmation_token=jJKBCgMK9sdMb-tgEkco
NGなURL:
https://company.localhost:3001/companies/confirmation?confirmation_token=iFe9BQvWXztHWegPn33v
追記ーーーーーーーーーーーー
ruby
1routes.rb 2 # サブドメイン company.localhost.com 3 # -------------------------------------------- 4 constraints subdomain: 'company' do 5 get '/', :to => 'companies#top', as: :company_top 6 scope module: :companies do 7 devise_for :companies, skip: [:registrations], controller: { 8 sessions: "companies/sessions", 9 passwords: "companies/passwords", 10 registrations: "companies/registrations", 11 confirmations: "companies/confirmations", 12 unlocks: "companies/unlocks", 13 invitations: 'companies/invitations' 14 } 15 devise_scope :company do 16 get 'companies/sign_up', :to => 'registrations#new', as: :company_registration_new 17 get 'companies/confirm', :to => 'registrations#confirm', as: :company_registration_complete 18 get 'companies/done', :to => 'registrations#done', as: :company_registration_done 19 post '/company_create', :to => "registrations#create", as: :company_registration_create 20 get '/password/done', :to => 'passwords#done', as: :company_password_done 21 post '/invitation/confirm', :to => 'invitations#confirm', as: :confirm_company_invitation 22 get '/invitation/done', :to => 'invitations#done' 23 put '/:id/config/done', :to => 'registrations#update', as: :update_company_registration 24 end 25 end 26 end
ruby
1app/views/companies/mailer/confirmation_instructins.html.erb 2 3<p>Welcome <%= @email %>!</p> 4 5<p>You can confirm your account email through the link below:</p> 6 7<p><%= link_to 'アカウントを有効にする', controller: 'companies/confirmations', action: 'create', confirmation_token: @token %></p> 8
ruby
1app/controllers/mailer.rb 2class Mailer < Devise::Mailer 3 4 # User 5 def confirmation_instructions(record, token, opts={}) 6 mail = super 7 if record.class == Company 8 mail.subject = "会社メールアドレス認証のお願い" 9 elsif ecord.class == Admin 10 mail.subject = "管理者アカウントのメールアドレス認証のお願い" 11 else # User 12 mail.subject = "アカウントのメールアドレス認証のお願い" 13 end 14 mail 15 end 16
ruby
1app/controllers/companies/confirmations_controller.rb 2# frozen_string_literal: true 3 4class Companies::ConfirmationsController < Devise::ConfirmationsController 5 # GET /resource/confirmation/new 6 # def new 7 # super 8 # end 9 10 # POST /resource/confirmation 11 # def create 12 # super 13 # end 14 15 # GET /resource/confirmation?confirmation_token=abcdef 16 # def show 17 # super 18 # end 19 20 # protected 21 22 # The path used after resending confirmation instructions. 23 def after_resending_confirmation_instructions_path_for(resource_name) 24 company_top_path 25 # super(resource_name) 26 end
ruby
1rails routes 2 Prefix Verb URI Pattern Controller#Action 3 letter_opener_web /letter_opener LetterOpenerWeb::Engine 4 root GET / 5 new_user_confirmation GET /users/confirmation/new(.:format) users/confirmations#new {:subdomain=>""} 6 user_confirmation GET /users/confirmation(.:format) users/confirmations#show {:subdomain=>""} 7 POST /users/confirmation(.:format) users/confirmations#create {:subdomain=>""} 8 users_sign_up GET /users/sign_up(.:format) users/registrations#new {:subdomain=>""} 9 user_registration POST /user_create(.:format) users/registrations#create {:subdomain=>""} 10 user_update_registration PUT /user_create(.:format) users/registrations#update {:subdomain=>""} 11 user_destroy_registration DELETE /user_create(.:format) users/registrations#destroy {:subdomain=>""} 12 company_top GET / companies#top {:subdomain=>"company"} 13 new_company_session GET /companies/sign_in(.:format) companies/sessions#new {:subdomain=>"company"} 14 company_session POST /companies/sign_in(.:format) companies/sessions#create {:subdomain=>"company"} 15 destroy_company_session DELETE /companies/sign_out(.:format) companies/sessions#destroy {:subdomain=>"company"} 16 new_company_confirmation GET /companies/confirmation/new(.:format) companies/confirmations#new {:subdomain=>"company"} 17 company_confirmation GET /companies/confirmation(.:format) companies/confirmations#show {:subdomain=>"company"} 18 POST /companies/confirmation(.:format) companies/confirmations#create {:subdomain=>"company"} 19 accept_company_invitation GET /companies/invitation/accept(.:format) companies/invitations#edit {:subdomain=>"company"} 20 remove_company_invitation GET /companies/invitation/remove(.:format) companies/invitations#destroy {:subdomain=>"company"} 21 new_company_invitation GET /companies/invitation/new(.:format) companies/invitations#new {:subdomain=>"company"} 22 company_invitation PATCH /companies/invitation(.:format) companies/invitations#update {:subdomain=>"company"} 23 PUT /companies/invitation(.:format) companies/invitations#update {:subdomain=>"company"} 24 POST /companies/invitation(.:format) companies/invitations#create {:subdomain=>"company"} 25 company_registration_new GET /companies/sign_up(.:format) companies/registrations#new {:subdomain=>"company"} 26 company_registration_complete GET /companies/confirm(.:format) companies/registrations#confirm {:subdomain=>"company"} 27 company_registration_done GET /companies/done(.:format) companies/registrations#done {:subdomain=>"company"} 28 company_registration_create POST /company_create(.:format) companies/registrations#create {:subdomain=>"company"} 29 company_password_done GET /password/done(.:format) companies/passwords#done {:subdomain=>"company"} 30 confirm_company_invitation POST /invitation/confirm(.:format) companies/invitations#confirm {:subdomain=>"company"} 31 invitation_done GET /invitation/done(.:format) companies/invitations#done {:subdomain=>"company" 32 33 34Routes for LetterOpenerWeb::Engine: 35clear_letters DELETE /clear(.:format) letter_opener_web/letters#clear 36delete_letter DELETE /:id(.:format) letter_opener_web/letters#destroy 37 letters GET / letter_opener_web/letters#index 38 letter GET /:id(/:style)(.:format) letter_opener_web/letters#show 39 GET /:id/attachments/:file(.:format) letter_opener_web/letters#attachment 40
回答1件
あなたの回答
tips
プレビュー