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,23 @@ 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 toggle_test + @problem = Problem.find(params[:id]) + @problem.update_attributes(test_allowed: !(@problem.test_allowed?) ) + respond_to do |format| + format.js { } + end end def turn_all_off @@ -136,7 +141,7 @@ problem.available = false problem.save end - redirect_to :action => 'list' + redirect_to action: :index end def turn_all_on @@ -145,7 +150,7 @@ problem.available = true problem.save end - redirect_to :action => 'list' + redirect_to action: :index end def stat