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"