Refactoring
This commit is contained in:
@@ -88,7 +88,8 @@ class Course < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.pluck_periods
|
||||
Course.uniq.pluck(:period).reject!(&:blank?).sort.reverse
|
||||
periods = Course.uniq.reorder('').pluck(:period).reject!(&:blank?) || []
|
||||
periods.sort.reverse
|
||||
end
|
||||
|
||||
def self.from_param(param)
|
||||
|
||||
@@ -25,7 +25,7 @@ class User < ActiveRecord::Base
|
||||
acts_as_paranoid
|
||||
|
||||
has_and_belongs_to_many :courses, order: 'full_name',
|
||||
conditions: "period = #{App.current_period}"
|
||||
conditions: "period = '#{App.current_period}'"
|
||||
|
||||
validates_length_of :login, within: 3..40
|
||||
validates_length_of :name, within: 3..40
|
||||
@@ -86,8 +86,12 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def courses_not_enrolled(period)
|
||||
Course.all(conditions: ['period = ? and hidden = ? and id not in (?)',
|
||||
period, false, courses])
|
||||
if courses.empty?
|
||||
Course.visible.where(period: period)
|
||||
else
|
||||
Course.where('period = ? and hidden = ? and id not in (?)',
|
||||
period, false, courses)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
Reference in New Issue
Block a user