我有一個用戶可以通過電子郵件發送的狀態報告,我希望在發送操作完成後將列sent_mail更新爲true。Update_all或update_attribute不會更新列
def send_status
date = Date.today
reports = current_user.reports.for_date(date)
ReportMailer.status_email(current_user, reports, date).deliver
reports.update_all(sent_mail: true)
end
和表類
AddSentMailToReports < ActiveRecord::Migration
def change
add_column :reports, :sent_mail, :boolean, default: false
end
end
然而,在控制檯,sent_mail仍設置爲false.Any想法爲什麼不起作用? 謝謝!
'undefined method'update_attribute'' because because'reports' is a'ActiveRecord :: Relation' – dukedave