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 @@ -81,11 +81,10 @@ redirect_to :action => 'list' end - def toggle_avail - problem = Problem.find(params[:id]) - problem.available = !(problem.available) - problem.save - redirect_to :action => 'list' + def toggle + @problem = Problem.find(params[:id]) + @problem.available = !(@problem.available) + @problem.save end def turn_all_off diff --git a/app/views/problems/list.rhtml b/app/views/problems/list.rhtml --- a/app/views/problems/list.rhtml +++ b/app/views/problems/list.rhtml @@ -23,7 +23,7 @@ <% for problem in @problems %> - "> + "> <% @problem=problem %> <%= in_place_editor_field :problem, :name, {}, :rows=>1 %> <%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %> @@ -32,7 +32,7 @@ <%= problem.available %> <%= problem.test_allowed %> - <%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %> + <%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %> <%= link_to '[Stat]', :action => 'stat', :id => problem.id %> <%= link_to '[Show]', :action => 'show', :id => problem %> <%= link_to '[Edit]', :action => 'edit', :id => problem %> @@ -41,7 +41,6 @@ <% end %> -
<%= link_to 'New problem', :action => 'new' %> diff --git a/app/views/problems/toggle.js.rjs b/app/views/problems/toggle.js.rjs new file mode 100644 --- /dev/null +++ b/app/views/problems/toggle.js.rjs @@ -0,0 +1,5 @@ +if @problem.available + page["prob-#{@problem.id}"].className = "available" +else + page["prob-#{@problem.id}"].className = "not-available" +end \ No newline at end of file