缺少模板notification_mailer / meeting_request_with_calendar与{:locale => [:en],:formats => [:ics],:handlers => [:erb,:builder,:coffee]}

时间:2014-01-03 05:19:17

标签: ruby-on-rails ruby actionmailer icalendar

我看到此代码用于发送日历邀请邮件。但是,它运行时会出现以下异常:

Missing template notification_mailer/meeting_request_with_calendar with {:locale=>[:en], :formats=>[:ics], :handlers=>[:erb, :builder, :coffee]}

    class MeetingNotification < ActionMailer::Base   # include Icalendar   def meeting_request_with_calendar
         mail(:to => "ashi_12@gmail.com", :subject => "iCalendar",
                      :from => "tester@gmail.com") do |format|
           format.ics {
           ical = Icalendar::Calendar.new
           e = Icalendar::Event.new
           e.start = DateTime.now.utc
           e.start.icalendar_tzid="UTC" # set timezone as "UTC"
           e.end = (DateTime.now + 1.day).utc
           e.end.icalendar_tzid="UTC"
           e.organizer "tester@gmail.com"
           e.uid "MeetingRequest"
           e.summary "Scrum Meeting"
           e.description <<-EOF
             Venue: Office
             Date: 16 August 2013
             Time: 10 am
           EOF
           ical.add_event(e)
           ical.publish
           ical.to_ical
           render :text => ical, :layout => false
          }
        end
   end
end

2 个答案:

答案 0 :(得分:2)

我很确定你不想发送一个ics格式的邮件。您希望以附加了ics的html格式发送邮件。类似的东西:

def send_ics(user, event)
  mail.attachments['example.ics'] = { :mime_type => 'text/calendar',
                                      :content => generate_ics(event) }
  mail(:to => user.email, :subject => "iCalendar", :from => "tester@gmail.com")
end

private 
def generate_ics(event)
  ical = Icalendar::Calendar.new
  ...
  ical.to_ical
end

答案 1 :(得分:1)

框架正在app / views / notification_mailer目录中查找模板(如meeting_request_with_calendar.erb文件)。期望模板被命名为meeting_request_with_calendar,因为这是您的方法的名称。该模板应该格式化电子邮件内容。