2016-10-19 57 views
0

我想在每次交易後發送郵件給商店的所有者。其他一切都已建立,但我似乎無法獲得生成的電子郵件地址。貝寶郵差挑戰與導軌

class PaymentNotifier < ActionMailer::Base 

def notify(payment_notification) 
    @payment_notification = payment_notification 
    mail to: **'xxxxxxxxx'**, subject: 'New order' 
    end 
end 

付款通知接觸到交易的詳細信息的系統: cart_id,LINE_ITEM_ID,PRODUCT_TITLE。

Line_item有一個cart_id列和一個product_id列。

產品具有store_id列。

商店有一個user_id列。

用戶有一個電子郵件地址

試圖找出我如何從我的郵件中訪問此電子郵件地址,並在交易後觸發電子郵件。

任何幫助,將不勝感激。

提前致謝!

+0

您使用的設計? – Sravan

+1

@Sravan是的,我是。爲什麼? –

回答

1

參考的相關項目,就可以得到user_email爲,

LineItem.find(@payment_notification.line_item_id).product.store.user.email 

梅勒,

class PaymentNotifier < ActionMailer::Base 

def notify(payment_notification) 
    @payment_notification = payment_notification 
    mail to: LineItem.find(@payment_notification.line_item_id).product.store.user.email, subject: 'New order' 
    end 
end 
+0

如果我使用'current_user.email' - 是不是隻發送給登錄用戶? –

+0

但你說電子郵件應該去店主? – Sravan

+0

如果你想發送郵件給logged_in用戶,你可以簡單地使用'current_user.email',但是你希望它發送給店主,請檢查我的答案。 – Sravan