Skip to content

Instantly share code, notes, and snippets.

@ckozus
Created March 13, 2015 15:26
Show Gist options
  • Save ckozus/42a7dbf6cc9385de2367 to your computer and use it in GitHub Desktop.
Save ckozus/42a7dbf6cc9385de2367 to your computer and use it in GitHub Desktop.
class User
has_one :plan
has_many :certificates
def remaining_certificates
plan.available - certificates.current_month.count
end
end
class Certificate
belongs_to :user
scope :current_month, -> { where(:created_at => [Time.zone.now.beggining_of_moth, Time.zone.now.end_of_moth]) }
end
class Plan < User
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment