Skip to content

Commit

Permalink
Get subject quiz working
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Mar 10, 2012
1 parent 4e2ca21 commit de1bb4a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

*.dump
config/database.yml
5 changes: 3 additions & 2 deletions app/controllers/subjects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def index

def quiz
@subject = current_object
@units = @subject.units.learned_by(current_user).random(params[:seed]).paginate(:select => 'units.*', :page => params[:page], :per_page => 1)
Subject.seed(params[:seed])
@units = @subject.units.learned_by(current_user).random.paginate(:page => params[:page], :per_page => 1).all
@units.empty? ? response_for(:quiz_complete) : response_for(:quiz)
end

Expand All @@ -50,7 +51,7 @@ def review; redirect_to_next_review; end
private

def force_seed
redirect_to quiz_subject_path(current_object, :page => (params[:page] || 1), :seed => rand(100)) if
redirect_to quiz_subject_path(current_object, :page => (params[:page] || 1), :seed => rand()) if
params[:seed].blank?
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/subjects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def subject_retention(subject)
end

def remaining_quiz
(count = @units.page_count - @units.current_page) <= 0 ?
(count = @units.total_pages - @units.current_page) <= 0 ?
"final item" :
"#{count} remaining"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/learning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class Learning < ActiveRecord::Base
# Named scopes
scope :for, lambda { |subject| {:conditions => "units.subject_id = #{subject.id}", :joins => "LEFT JOIN units ON units.id = unit_id"}}
scope :today, lambda { {:conditions => ['learnings.created_at > ? and learnings.created_at < ?', Time.zone.now.beginning_of_day, Time.zone.now.end_of_day]} }
scope :not_deferred, :conditions => {:deferred => false }
scope :not_deferred, :conditions => { :deferred => false }
scope :recent, :order => 'learnings.created_at DESC, learnings.id DESC'
end
6 changes: 6 additions & 0 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class Subject < ActiveRecord::Base
belongs_to :owner, :class_name => 'User'

has_permalink :name

class << self
def seed(seed)
connection.execute(sanitize_sql(["SELECT SETSEED(?)", seed]))
end
end

# Import the question and answers from the given file into this
# subject
Expand Down
6 changes: 3 additions & 3 deletions app/models/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class Unit < ActiveRecord::Base
}

scope :learned_by, lambda { |user|
{ :joins => "LEFT JOIN learnings ON units.id = learnings.unit_id AND learnings.deferred = 0 AND learnings.user_id = #{user.id}",
{ :joins => "LEFT JOIN learnings ON units.id = learnings.unit_id AND learnings.deferred = false AND learnings.user_id = #{user.id}",
:conditions => "learnings.unit_id IS NOT NULL" }
}

scope :empty, :conditions => ["answer IS NULL OR answer = ''"]

# Get units in random order in a repeateable way (hence the seed)
scope :random, lambda { |seed| { :order => "RAND(#{seed || 1})" } }
# Get units in random order in a repeateable way (must do SETSEED(seed) first)
scope :random, { :order => "RANDOM()" }
scope :ordered, { :order => 'units.position' }

class << self
Expand Down
2 changes: 1 addition & 1 deletion app/views/associations/_show.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
%p
= link_to_remote h(association.body), :url => edit_association_path(association), :method => :get, :html => { :key => 'a', :id => 'edit_hint' }
= link_to association.body, :url => edit_association_path(association), :method => :get, :html => { :key => 'a', :id => 'edit_hint' }, :remote => true
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
%li
%a{:href => '#'} About
%li
= mail_to("ryan@yfactorial.com", 'Contact')
= mail_to("ryan.daigle@gmail.com", 'Contact')
%p
copyright yFactorial, LLC 2008

0 comments on commit de1bb4a

Please sign in to comment.