You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
1010 B
24 lines
1010 B
class ExerciseBank < ApplicationRecord
|
|
# container_type: Poll 问卷; Exercise试卷
|
|
belongs_to :user
|
|
belongs_to :course_list
|
|
|
|
has_many :exercise_bank_questions, :dependent => :destroy
|
|
has_many :polls, dependent: :nullify
|
|
has_many :exercises, dependent: :nullify
|
|
|
|
# def course_list_name
|
|
# self.course_list ? self.course_list.name : ""
|
|
# end
|
|
#
|
|
scope :myself, -> (user_id){where(user_id: user_id)}
|
|
scope :find_by_container, lambda { |id,type| where(container_id: id,container_type:type)}
|
|
scope :find_by_c_type, lambda { |keywords| where(container_type: keywords) unless keywords.blank?}
|
|
scope :public_exercises, -> {where(is_public: true)}
|
|
scope :exercise_bank_search, lambda { |keywords|
|
|
where("name LIKE ?", "%#{keywords}%") unless keywords.blank?}
|
|
|
|
validates :name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" }
|
|
validates :description, length: { maximum: 100, too_long: "100 characters is the maximum allowed" }
|
|
|
|
end |