announcement-test/app/models/announcement_setting.rb

13 lines
366 B
Ruby

class AnnouncementSetting
include Mongoid::Document
include Mongoid::Timestamps
field :top_limit, type: Integer, :default => 0
def self.check_limit_for_user(user_id, b_id = nil)
limit = self.first.top_limit
return true if limit == 0
count = Bulletin.where(:is_top => true, :create_user_id => user_id, :id.ne => b_id).count
return count < limit
end
end