Potrzebuję dostosować zapomniane instrukcje dotyczące haseł do obsługi subdomeny. Śledzę z instrukcjami na stronie opracować przesłonić mailera, kontroler i dodać pomocnika subdomeny itp wymienione:Railsy przekazują request.subdomain do niestandardowego layoutu pocztowego Devise
controllers/password_controller.rb
class PasswordsController < Devise::PasswordsController
def create
@subdomain = request.subdomain
super
end
end
routes.rb
devise_for :users, controllers: { passwords: 'passwords' }
devise.rb
config.mailer = "UserMailer"
koperty/użytkownik _mailer.rb
class UserMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
def confirmation_instructions(record, opts={})
devise_mail(record, :confirmation_instructions, opts)
end
def reset_password_instructions(record, opts={})
devise_mail(record, :reset_password_instructions, opts)
end
def unlock_instructions(record, opts={})
devise_mail(record, :unlock_instructions, opts)
end
end
views/user_mailer/reset_password_instructions.html.erb
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token, :subdomain => @subdomain) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
pomocnicy/subdomain_helper.rb
module SubdomainHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
host = Rails.application.config.action_mailer.default_url_options[:host]
[subdomain, host].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
end
super
end
end
environment.rb
config.to_prepare do
Devise::Mailer.class_eval do
helper :subdomain
end
end
teraz ten kod jest najgorszy króla, ale po prostu nie może uzyskać wartości @domdomaina w widoku mailera. Jeśli zastąpię @domubain z zakodowanym na stałe ciągiem, to poprawny adres URL zostanie przekazany w e-mailu, więc wiem, że kod jest poprawny.
Jak uzyskać zmienną instancji @ subdomena zdefiniowaną w kontrolerze w widoku programu pocztowego?
Może to się łatwiejsze, kiedy to połączył się: https://github.com/plataformatec/devise/pull/2207 –
w końcu dostał szansę to sprawdzić - i to wszystko działa, zgadzają się, że czuje się trochę nieczyste, ale naprawdę nie mogę znaleźć tutaj prostego, czystego rozwiązania - dziękuję, to ogromna pomoc! –