2014-09-05 50 views
0

我是一名開始的程序員,我剛剛在我的Ruby on Rails 4 Web應用程序中實現了Mailboxer。一切都很好,但我希望收件人是用戶的名字,而不是他們的電子郵件。我搜索了幾個小時,找不到確切的答案。這是我的代碼,儘管它幾乎完全是文檔指示的。郵箱將用戶電子郵件中的收件人更改爲用戶名RoR 4

配置/初始化/ mailboxer.rb

Mailboxer.setup do |config| 

    #Configures if you application uses or not email sending for Notifications and Messages 
    config.uses_emails = true 

    #Configures the default from for emails sent for Messages and Notifications 
    config.default_from = "[email protected]" 

    #Configures the methods needed by mailboxer 
    config.email_method = :mailboxer_email 
    config.name_method = :name 

    #Configures if you use or not a search engine and which one you are using 
    #Supported engines: [:solr,:sphinx] 
    config.search_enabled = false 
    config.search_engine = :solr 

    #Configures maximum length of the message subject and body 
    config.subject_max_length = 255 
    config.body_max_length = 32000 
end 

應用程序/模型/ user.rb

acts_as_messageable 

    ... 

    def name 
    email 
    end 

    def mailboxer_email(object) 
    email 
    end 

任何幫助將不勝感激。我嘗試過使用代碼,但我無法完全正確地調整組合。非常感謝!

回答

0

這基本上是在接收郵件用戶代理,這需要一個郵件首部

To: somebody <[email protected]> 

,只顯示「某人」的特徵。構建頭一種方法應該是

def mailboxer_email(object) 
    "#{name} <#{email}>" 
end 

如果變量name包含所需郵件用戶代理來顯示用戶名。

相關問題