2012-10-11 2 views
6

send_confirmation_instructions을 재정의하는 방법을 다음과 같이 :고안, 나는 방법 'send_confirmation_instructions'을 무시하기 위해 노력하고있어

http://trackingrails.com/posts/devise-send-confirmation-mail-manually-or-delay-them

로 :

def send_confirmation_instructions 
    generate_confirmation_token! if self.confirmation_token.nil? 
    ::Devise.mailer.delay.confirmation_instructions(self) 
end 

이 더 이상 작동하지 보인다 고안의 최신 버전. devise 문서는 컨트롤러가 아닌 모델을 오버라이드하는 방법을 보여줍니다. 개발자 모델을 재정의하는 방법에 대한 제안 사항이 있으십니까? 감사합니다

답변

7

Devise를 설정할 때 어떤 모델이 작동하는지 (예 : User) 알려줍니다. 그 방법의 대부분은 그 클래스에 적용됩니다. 그래서 이것이 당신이 물건을 무력화하려는 곳입니다.

정확하게 읽고 있다면 정확히 무엇을하고 싶은지를 나타내는 lib/devise/models/authenticatable.rb에있는 Devise 코드의 주석이 있습니다.

# This is an internal method called every time Devise needs 
    # to send a notification/mail. This can be overriden if you 
    # need to customize the e-mail delivery logic. For instance, 
    # if you are using a queue to deliver e-mails (delayed job, 
    # sidekiq, resque, etc), you must add the delivery to the queue 
    # just after the transaction was committed. To achieve this, 
    # you can override send_devise_notification to store the 
    # deliveries until the after_commit callback is triggered: 
    # 
    #  class User 
    #  devise :database_authenticatable, :confirmable 
    # 
    #  after_commit :send_pending_notifications 
    # 
    #  protected 
    # 
    #  def send_devise_notification(notification) 
    #   pending_notifications << notification 
    #  end 
    # 
    #  def send_pending_notifications 
    #   pending_notifications.each do |n| 
    #   devise_mailer.send(n, self).deliver 
    #   end 
    #  end 
    # 
    #  def pending_notifications 
    #   @pending_notifications ||= [] 
    #  end 
    #  end 
    # 
    def send_devise_notification(notification) 
    devise_mailer.send(notification, self).deliver 
    end 
+0

내 user.rb 파일에 "send_devise_notification"을 추가 하시겠습니까? 나는 그것을 시도했고 호출되지 않았다 ... – AnApprentice

+0

예, 사용자 모델에서'send_devise_notification'을 무시합니다. 나는 Devise의 최신 버전으로 알림을 가로 챌 수있었습니다 (로그에 somethig를 보냈습니다). 그러나 모든 것을 작동 시키려면 주석을 읽으십시오. 메서드를 정의하는 것뿐만 아니라'after_commit' 필터를 추가하여 지연된 작업 (또는 무엇이든) 큐를 구축해야합니다. –

+0

감사합니다. 그러나 "send_confirmation_instructions"의 위치가 아닙니다. 해당 메소드 "send_confirmation_instructions"를 수정해야합니다. – AnApprentice

0

devise-async을 사용하지 않는 이유는 무엇입니까?

Usage 

Devise >= 2.1.1 

Include Devise::Async::Model to your Devise model 

class User < ActiveRecord::Base 
    devise :database_authenticatable, :confirmable # etc ... 

    include Devise::Async::Model # should be below call to `devise` 
end 

Devise < 2.1.1 

Set Devise::Async::Proxy as Devise's mailer in config/initializers/devise.rb: 

# Configure the class responsible to send e-mails. 
config.mailer = "Devise::Async::Proxy" 

All 

Set your queuing backend by creating config/initializers/devise_async.rb: 

# Supported options: :resque, :sidekiq, :delayed_job 
Devise::Async.backend = :resque 
+0

devise-async는 사용자에게 설정 한 가상 속성을 저장하지 않기 때문에 (attr_accessor). – AnApprentice

+0

최신 버전의 장치를 사용하려는 경우 [해당 문서] (https://github.com/mhfs/devise-async#devise--40)에서 볼 수 있듯이 더 이상 옵션이 아닙니다. 지원하지 않습니다. Devise> = 4.0 –

관련 문제