我正在尝试将我的 PDF 附加到电子邮件中。但是,当我单击链接时,出现以下错误undefiined method 'user'
,我有以下设置:
控制器
def index
@hospital_bookings = HospitalBooking.scoped
hospital_booking = @hospital_bookings
@user = User.all
if params[:format] == "pdf"
@hospital_bookings = @hospital_bookings.where(:day => Date.today.beginning_of_month..Date.today.end_of_month)
end
respond_to do |format|
format.html
format.pdf do
render :pdf => "#{Date.today.strftime("%B")} Overtime Report",
:header => {:html => {:template => 'layouts/pdf.html.erb'}}
OvertimeMailer.overtime_pdf(hospital_booking).deliver
end
end
end
overtime_mailer.rb
class OvertimeMailer < ActionMailer::Base
default :from => DEFAULT_FROM
def overtime_pdf(hospital_booking)
@hospital_bookings = hospital_booking
attachments["Overtime Report.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "Overtime Report",:template => 'layouts/pdf.html.erb'))
mail(:to => hospital_booking.user.email, :subject => "Overtime Report")
end
end
错误发生在以下行mail(:to => hospital_booking.user.email, :subject => "Overtime Report"