2012-10-11 20 views
6

send_confirmation_instructions geçersiz kılmak nasıl burada gösterildiği gibi:tasarlamak, ben yöntemi 'send_confirmation_instructions' geçersiz kılmak çalışıyorum

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

ile:

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

Bu artık çalışmak gibi görünüyor geliştirmenin son sürümü. Uygulama tasarlayıcıları, bir denetleyiciyi nasıl geçersiz kılacağını, ancak bir modelin nasıl yapıldığını gösterir. Bir düzenleme modelini nasıl geçersiz kılacağınıza dair herhangi bir öneriniz var mı? Teşekkürler

cevap

7

Devise'yi kurduğunuzda, üzerinde çalıştığınız modeli (ör. Kullanıcı); yöntemlerinin çoğu/çoğu, o sınıfa uygulanır. Yani, bu şeyleri geçersiz kılmak isteyeceğiniz yer.

İşte doğru okuyorsam, hemen hemen tam olarak ne yapmak istediğinizi açıklayan lib/devise/models/authenticatable.rb adresindeki Devise kodundan bir yorum.

# 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

Teşekkür ederim, user.rb dosyasına "send_devise_notification" eklediniz mi? Bunu denedim ve aramadı ... – AnApprentice

+0

Evet, Kullanıcı modelinizde 'send_devise_notification' seçeneğini geçersiz kılın. Devise'nin şu anki bir sürümü ile bildirimi (sadece çalışmayı kanıtlamak için günlüğüne bir şeyler yolladım) engelleyebildim. Ama her şeyin işe yaraması için, yorumu oku - sadece yöntemi tanımlama meselesi değil, aynı zamanda gecikmiş işi (veya her neyse) kuyruğunu oluşturmak için 'after_commit' süzgecini de eklemelisiniz. –

+0

Teşekkürler ama bu "send_confirmation_instructions" nerede yaşıyor? ve bu yöntemi "send_confirmation_instructions" – AnApprentice

0

Neden 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 kullanıcı üzerinde ayarladığınız sanal öznitelikleri saklamıyor (attr_accessor). – AnApprentice

+0

Eğer en son sürümü kullanmak istiyorsanız, artık bu bir seçenek değildir, [docs] 'da görebileceğiniz gibi (https://github.com/mhfs/devise-async#devise--40) desteklemezler. Devise> = 4.0 –

İlgili konular