2012-02-08 46 views
3

我通過resque發送電子郵件。所有電子郵件發送正確,除了這一個,它在本地發送罰款,但在登臺服務器上失敗。通過resque發送電子郵件:對象視爲散列

它似乎將'Admin'對象視爲散列而不是將其視爲管理對象。有任何想法嗎?

account.rb

class Account < ActiveRecord::Base 
    after_commit :send_welcome_email 

    def send_welcome_email 
     SubscriptionNotifier.welcome(self).deliver 
    end 

end 

subscription_notifier.rb

class SubscriptionNotifier < ActionMailer::Base 

    def welcome(account) 
    @subscriber = account 
    mail(:to => account.admin.email, :subject => "Welcome!") 
    end 

end 

Resque錯誤

SubscriptionNotifier Arguments 

    "welcome" 
    {"account"=>{"address_line1"=>nil, "address_line2"=>nil, "city"=>nil, "created_at"=>"2012-02-08T10:56:22-08:00", "currency"=>"United States Dollar (USD)", "deleted_at"=>nil, "description"=>nil, "email"=>"[email protected]", "full_domain"=>"www.test.net", "id"=>3, "initial_plan"=>nil, "latitude"=>nil, "longitude"=>nil, "name"=>"macs", "phone"=>nil, "setup_steps_complete"=>0, "state"=>nil, "time_zone"=>"Pacific Time (US & Canada)", "updated_at"=>"2012-02-08T10:56:22-08:00", "website"=>nil, "zip"=>nil}} 

Exception 
    NoMethodError 
Error 
    undefined method `admin' for #<Hash:0x0000000585aa70> 
+0

你用來實際調用'SubscriptionNotifier.welcome(...)。deliver'的代碼是什麼? – 2012-02-08 19:12:48

+0

您可以添加Resque工人代碼並顯示您如何調用它? – bensie 2012-02-08 19:26:19

+0

我更新了帖子。 Resque工作者代碼是subscription_notifier中的內容。這就好像Rails env沒有加載,但我用'rake resque:work QUEUE ='*'RAILS_ENV = staging' – 99miles 2012-02-08 19:51:34

回答

0

您將需要通過運行「耙環境resque加載環境:工作隊列= '*'RAILS_ENV =分期'

那就是除非你有

任務 「resque:設置」=>:環境在resque.rake文件中定義

。在subscription_notifier.rb在account.rb

def send_welcome_email 
     SubscriptionNotifier.welcome(self.admin.email).deliver 
    end 

def welcome(account_admin_email) 
    @subscriber = account 
    mail(:to => account_admin_email, :subject => "Welcome!") 
    end 

我有同樣的錯誤,顯然是要傳遞account爲散列,它具有:

0

試試這個沒有電子郵件admin方法。因此,只需在send_welcome_email方法中獲取電子郵件並將其作爲參數傳遞,而不是傳遞散列並嘗試以welcome方法訪問電子郵件。

注:爲@subscriber,你需要傳遞的參數,就像電子郵件,在電子郵件模板模型在歡迎方法

希望這有助於例如使用self.admin.name@name = account_admin_name

1

我想你應該只將賬戶ID傳入隊列,並讓工作人員在執行其執行方法時獲取Account對象。這應該會減少你的哈希困境。