Rails - 如果选中复选框,则将项目添加到电子邮件主题

时间:2013-05-15 21:55:33

标签: ruby-on-rails checkbox mailer

我正在尝试添加“紧急!”在提交表单并选中“紧急”复选框时,将电子邮件作为确认信息发送到我的主题的开头。

我基本上无法弄清楚如何找出复选框的值是“true”还是“false”。

该复选框存储在我的门票模型下:urgent_reminder列。

有谁知道我在这里做错了什么?

这是我的Newticket_Mailer.rb

class NewticketMailer < ActionMailer::Base
default from: "ExampleFrom@Email.org"

def urgent
  if @ticket.urgent_reminder == true
    puts "URGENT!"
  else 
  end
end

def email_subjectCreation
  urgent 'Facilities Ticket Created for ' + @ticket.school.name
end

def ticket_creation(ticket)
  @ticket = ticket
  mail to: @ticket.mailing_list.name, subject: email_subjectCreation, reply_to:   @ticket.submitter.full_email
end

end

1 个答案:

答案 0 :(得分:1)

你正在写信给stdout。尝试更贴近的事情:

def urgent
  'URGENT: ' if @ticket.urgent_reminder
end

def subject
  "#{urgent}Facilities Ticket Created for #{@ticket.school.name}"
end

然而,我可能会使访问器更像Ruby-esque:

def urgent
  'URGENT: ' if @ticket.urgent?
end