diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-19 13:48:09 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-27 23:02:44 +0200 |
commit | 4e23bfe03a8d3123dfcbf99c374b20b28db150af (patch) | |
tree | ca80322fe9c61746640878d867e28ac01ccd7dfb /app | |
parent | Rename method in User model (diff) | |
download | recruiting-webapp-4e23bfe03a8d3123dfcbf99c374b20b28db150af.tar.gz recruiting-webapp-4e23bfe03a8d3123dfcbf99c374b20b28db150af.tar.bz2 recruiting-webapp-4e23bfe03a8d3123dfcbf99c374b20b28db150af.zip |
Replace two functions in User model with named scopes in Answer model
User::my_recruits_answers with Answer::of_mentored_by,
User::my_recruits_answers_in_category with chaining
Answer::of_mentored_by and Answer::in_category.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/answer.rb | 6 | ||||
-rw-r--r-- | app/models/user.rb | 8 | ||||
-rw-r--r-- | app/views/answers/my_recruits.dryml | 2 | ||||
-rw-r--r-- | app/views/answers/my_recruits_cat.dryml | 2 |
4 files changed, 8 insertions, 10 deletions
diff --git a/app/models/answer.rb b/app/models/answer.rb index fd2781c..7830389 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -17,6 +17,12 @@ class Answer < ActiveRecord::Base belongs_to :question has_many :comments + named_scope :of_mentored_by, lambda { |mentor| { + :joins => :owner, :conditions => { 'users.mentor_id', mentor } } } + + named_scope :in_category, lambda { |category| { + :joins => :question, :conditions => { 'questions.question_category_id', category} } } + validates_uniqueness_of :question_id, :scope => :reference, :if => :reference validates_uniqueness_of :question_id, :scope => :owner_id, :unless => :reference diff --git a/app/models/user.rb b/app/models/user.rb index 26732fc..7b9c5f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -102,14 +102,6 @@ class User < ActiveRecord::Base Question.unanswered_grouped(id) + Question.unanswered_ungrouped(id) end - def my_recruits_answers - Answer.all :joins => :owner, :conditions => ['users.mentor_id = ?', id] - end - - def my_recruits_answers_in_category(cat) - Answer.all :joins => [:question, :owner], :conditions => ['questions.question_category_id = ? AND users.mentor_id = ?', cat, id] - end - def answered_all_questions? Question.unanswered_grouped(id).count.zero? && Question.unanswered_ungrouped(id).count.zero? end diff --git a/app/views/answers/my_recruits.dryml b/app/views/answers/my_recruits.dryml index e61e4b6..6239d38 100644 --- a/app/views/answers/my_recruits.dryml +++ b/app/views/answers/my_recruits.dryml @@ -1,6 +1,6 @@ <index-page> <content:> - <repeat with="¤t_user.my_recruits_answers"> + <repeat with="&Answer.of_mentored_by(current_user)"> <card/> </repeat> </content:> diff --git a/app/views/answers/my_recruits_cat.dryml b/app/views/answers/my_recruits_cat.dryml index 8b2d4f3..e80297c 100644 --- a/app/views/answers/my_recruits_cat.dryml +++ b/app/views/answers/my_recruits_cat.dryml @@ -1,6 +1,6 @@ <index-page> <content:> - <repeat with="¤t_user.my_recruits_answers_in_category(params[:id])"> + <repeat with="&Answer.of_mentored_by(current_user).in_category(params[:id])"> <card/> </repeat> </content:> |