# HG changeset patch # User Nattee Niparnan # Date 2016-06-22 15:28:07 # Node ID 9fc5999b7c8e8e8921cf8708c3da77e9f660b9ce # Parent 47db9776ed2ef45261f80b544fd53c2944f9b9d4 problem toggle on/off diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -7,8 +7,7 @@ in_place_edit_for :problem, :full_score def index - list - render :action => 'list' + @problems = Problem.find(:all, :order => 'date_added DESC') end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) @@ -17,11 +16,7 @@ :do_manage, :do_import, :update ], - :redirect_to => { :action => :list } - - def list - @problems = Problem.find(:all, :order => 'date_added DESC') - end + :redirect_to => { :action => :index } def show @problem = Problem.find(params[:id]) @@ -45,7 +40,7 @@ @problem.description = @description if @problem.save flash[:notice] = 'Problem was successfully created.' - redirect_to :action => 'list' + redirect_to action: :index else render :action => 'new' end @@ -61,10 +56,10 @@ @problem.date_added = Time.new if @problem.save flash[:notice] = 'Problem was successfully created.' - redirect_to :action => 'list' + redirect_to action: :index else flash[:notice] = 'Error saving problem' - redirect_to :action => 'list' + redirect_to action: :index end end @@ -121,13 +116,15 @@ def destroy Problem.find(params[:id]).destroy - redirect_to :action => 'list' + redirect_to action: :index end def toggle @problem = Problem.find(params[:id]) - @problem.available = !(@problem.available) - @problem.save + @problem.update_attributes(available: !(@problem.available) ) + respond_to do |format| + format.js {} + end end def turn_all_off @@ -136,7 +133,7 @@ problem.available = false problem.save end - redirect_to :action => 'list' + redirect_to action: :index end def turn_all_on @@ -145,7 +142,7 @@ problem.available = true problem.save end - redirect_to :action => 'list' + redirect_to action: :index end def stat diff --git a/app/views/problems/toggle.js.rjs b/app/views/problems/toggle.js.rjs deleted file mode 100644 --- a/app/views/problems/toggle.js.rjs +++ /dev/null @@ -1,6 +0,0 @@ -if @problem.available - page["prob-#{@problem.id}"].className = "available" -else - page["prob-#{@problem.id}"].className = "not-available" -end -page["prob-#{@problem.id}-avail"].innerHTML = @problem.available.to_s diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,8 @@ resources :sites + resources :problem + resources :grader_configuration, controller: 'configurations' match 'tasks/view/:file.:ext' => 'tasks#view'