ruby on rails - Activerecord conditions and named scope - undefined method `created_at' -
subscriber has_and_belongs_to_many :skills. skill has_many :positions in subscriber.rb:
scope :notify_today, includes(:skills => :positions). where("positions.created_at > ? , positions.created_at > ?", 1.day.ago, self.created_at) basically want find subscribers have positions 1) created 1.day.ago , 2) created after subscriber
the error occurs because class of self here class, not subscriber, wanted.
as solution, can make lamda , pass in parameter created_at: (i presume scope working otherwise, because have not tested your scope code specifically)
scope :notify_today, lambda { |created_at| includes(:skills => :positions). where("positions.created_at > ? , positions.created_at > ?", 1.day.ago, created_at) } and use it:
@subscribers = notify_today(time.now)
Comments
Post a Comment