Subscriber
has_and_belongs_to_many :skills.
Skill
has_many :positions
in subscriber.rb:
scope :notify_today,
includes(:skills => :positions).
开发者_如何学Python where("positions.created_at > ? AND positions.created_at > ?",
1.day.ago, self.created_at)
Basically I want to find all subscribers that have positions 1) created 1.day.ago AND 2) created after the subscriber
The error occurs because the class of self
here is Class
, not Subscriber
, as is wanted.
As a solution, you can make a lamda like this and pass in the parameter for created_at
:
(I presume your scope is working otherwise, because I have not tested this with your scope code specifically)
scope :notify_today,
lambda { |created_at| includes(:skills => :positions).
where("positions.created_at > ? AND positions.created_at > ?",
1.day.ago, created_at) }
And use it:
@subscribers = notify_today(Time.now)
精彩评论