2012-10-11 9 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 का नवीनतम संस्करण। डिवाइज़ डॉक्स दिखाते हैं कि नियंत्रक को ओवरराइड कैसे करें लेकिन मॉडल नहीं। एक devise मॉडल को ओवरराइड करने के बारे में कोई सुझाव? धन्यवाद

उत्तर

7

जब आप डेविस सेट करते हैं, तो आप इसे बताते हैं कि यह किस मॉडल पर काम कर रहा है (उदा। उपयोगकर्ता); इसके कई तरीके/उसके बाद अधिकांश वर्ग उस वर्ग पर लागू होते हैं। तो वह जगह है जहां आप सामान को ओवरराइड करना चाहते हैं।

यहां lib/devise/models/authenticatable.rb पर डेविस कोड से एक टिप्पणी है जो ठीक से पढ़ रहा है, तो लगभग वही वर्णन करता है जो आप करना चाहते हैं।

# 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' ओवरराइड करें। मैं डेविस के वर्तमान संस्करण के साथ अधिसूचना को अवरुद्ध करने में सक्षम था (मैंने इसे साबित करने के लिए लॉग में कुछ भेजा है)। लेकिन सब कुछ काम करने के लिए, टिप्पणी पढ़ें - यह विधि को परिभाषित करने की बात नहीं है, आपको देरी वाली नौकरी (या जो कुछ भी) कतार बनाने के लिए '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

यदि आप devise के नवीनतम संस्करण का उपयोग करना चाहते हैं तो यह अब एक विकल्प नहीं है, जैसा कि आप [उनके दस्तावेज़] में देख सकते हैं (https://github.com/mhfs/devise-async#devise--40) वे समर्थन नहीं करते डेविस> = 4.0 –

संबंधित मुद्दे