ruby-on-rails – 如果条件为真,如何添加到选项哈希?
发布时间:2020-12-17 03:06:23 所属栏目:百科 来源:网络整理
导读:在我的Rails项目中,我有这个邮件程序类: class ProjectMailer ActionMailer::Base def send_project_link(delivery) @delivery = delivery mail(:from = @delivery.sender_email,:to = @delivery.recipient_email,:bcc = [@delivery.sender_email],:subject
在我的Rails项目中,我有这个邮件程序类:
class ProjectMailer < ActionMailer::Base def send_project_link(delivery) @delivery = delivery mail(:from => @delivery.sender_email,:to => @delivery.recipient_email,:bcc => [@delivery.sender_email],:subject => @delivery.subject) end end 包含或不包含键/值对的最简洁方法是什么:哈希中的bcc,取决于是给出了真还是假? 谢谢你的帮助. 解决方法
要在选项中不包含:bcc键,您可以这样做:
class ProjectMailer < ActionMailer::Base def send_project_link(delivery,send_with_bcc=false) @delivery = delivery mail_options = { :from => @delivery.sender_email,:subject => @delivery.subject } mail_options[:bcc] = [@delivery.sender_email] if send_with_bcc mail(mail_options) end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |