0

我正在Ruby 2.4.1中的Rails 5.1.2應用程序。我創建一個簡單的郵件使用在類如下所示:Rails 5.1郵件錯誤的參數數量0預計2

class PagingMailer < ApplicationMailer 
     include SendGrid 
     default from: Rails.application.secrets.no_reply_email 

     def message(paging_id, email) 
     @paging = Paging.find(paging_id) 
     mail to: email, subject: "#{@paging.user.username} has sent you a message" 
     end 
    end 

PagingMailer類的message方法採用paging_id(整數)的參數,被傳遞的電子郵件地址的第二個參數(串)。最初我有一個sidekiq工人被解僱,並且它不會給出錯誤數量的參數,給出0預期的2例外。

所以我啓動了一個滑軌控制檯,並試圖做一個簡單的測試,讓sidekiq避開以防萬一。

Loading development environment (Rails 5.1.2) 
irb(main):001:0> PagingMailer.message(33, "[email protected]").deliver 
PagingMailer#message: processed outbound mail in 69.1ms 
ArgumentError: wrong number of arguments (given 0, expected 2) 
    from app/mailers/paging_mailer.rb:5:in `message' 
    from app/mailers/paging_mailer.rb:7:in `message' 
    from (irb):1 

stacktrace指向消息方法中的第5行和第7行,這裏的常用主題是email參數。

作爲一個測試,我嘗試刪除第二個參數和硬編碼「[email protected]」到郵件:部分,所以該方法只會採取一個參數paging_id。當我火從Rails的控制檯,我得到如下:

irb(main):003:0> PagingMailer.message(33).deliver 
PagingMailer#message: processed outbound mail in 27.4ms 
ArgumentError: wrong number of arguments (given 0, expected 1) 
    from app/mailers/paging_mailer.rb:5:in `message' 
    from app/mailers/paging_mailer.rb:7:in `message' 

我從字面上傳遞參數的方法和它沒有看到它,即使它被作爲一個對象傳遞。

應該指出我的應用程序中有一些其他的郵件程序,它們的配置類似於使用2個參數並且它們正確執行。但是,我正在努力拼湊這個特定的郵件。

不知道我是否錯過了一些完全明顯的東西,或者這可能是某種Rails錯誤。

任何幫助,您可以提供非常感謝。

+0

我認爲你的問題與SendGrid設置有關。擦除'包括SendGrid'並測試是否有效。 –

+0

@PapayaLabs不,這不是問題。我的其他郵件類使用相同的包含聲明和工作就好了。我通過您的請求刪除了它,併產生相同的異常。 – nulltek

+0

所以也許在#{@paging.user.username}。我不知道你的尋呼模式如何。我沒有看到任何其他問題。 –

回答

2

更改方法「消息」的名稱。 ActionMailer :: Base定義了一個名爲'message'的attr_internal,所以創建了讀寫實例方法,並且覆蓋它。

相關問題