Refactoring

This commit is contained in:
2015-09-05 23:58:22 -04:00
parent 5be138e890
commit 580098eaf1
8 changed files with 92 additions and 110 deletions

View File

@@ -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)

View File

@@ -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