Current user is a session concept, are you sure you are doing things in the correct place?
Maybe you are doing something in a active record hook that should be a method called by the controller...
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0bc3a8c2-8d47-4cea-b6f0-3cedd760a15c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class Attendance < ApplicationRecord
ATTENDANCE_EDITABLE_VALIDITY = 7
before_save :is_editable?
belongs_to :attendance_detail
def is_editable? errors.add(:attendance, 'modification is not allowed.') if attendance_detail.created_at.present? && (Time.zone.now.to_date - attendance_detail.created_at.to_date).to_i >= ATTENDANCE_EDITABLE_VALIDITY unless current_user.super_admin? || current_user.admin? errors.empty? endend