Commit 1c73a0c6140d6eba44f3693d6569d49214b474fe
1 parent
f8e154db
Exists in
master
and in
1 other branch
choice activation
Showing
3 changed files
with
60 additions
and
0 deletions
Show diff stats
app/controllers/choices_controller.rb
| @@ -57,6 +57,55 @@ class ChoicesController < InheritedResources::Base | @@ -57,6 +57,55 @@ class ChoicesController < InheritedResources::Base | ||
| 57 | end | 57 | end |
| 58 | end | 58 | end |
| 59 | end | 59 | end |
| 60 | + | ||
| 61 | + def update_from_abroad | ||
| 62 | + authenticate | ||
| 63 | + @question = current_user.questions.find(params[:question_id]) | ||
| 64 | + @choice = @question.choices.find(params[:id]) | ||
| 65 | + | ||
| 66 | + respond_to do |format| | ||
| 67 | + if @choice.activate! | ||
| 68 | + logger.info "successfully activated choice #{@choice.inspect}" | ||
| 69 | + format.xml { render :xml => true } | ||
| 70 | + format.json { render :json => true } | ||
| 71 | + else | ||
| 72 | + logger.info "failed to activate choice #{@choice.inspect}" | ||
| 73 | + format.xml { render :xml => @choice.to_xml(:methods => [:data, :votes_count, :wins_plus_losses])} | ||
| 74 | + format.json { render :json => @choice.to_json(:methods => [:data])} | ||
| 75 | + end | ||
| 76 | + end | ||
| 77 | + end | ||
| 78 | + | ||
| 79 | + def activate | ||
| 80 | + authenticate | ||
| 81 | + @question = current_user.questions.find(params[:question_id]) | ||
| 82 | + @choice = @question.choices.find(params[:id]) | ||
| 83 | + respond_to do |format| | ||
| 84 | + if @choice.activate! | ||
| 85 | + format.xml { render :xml => @choice.to_xml, :status => :created } | ||
| 86 | + format.json { render :json => @choice.to_json, :status => :created } | ||
| 87 | + else | ||
| 88 | + format.xml { render :xml => @choice.errors, :status => :unprocessable_entity } | ||
| 89 | + format.json { render :json => @choice.to_json } | ||
| 90 | + end | ||
| 91 | + end | ||
| 92 | + end | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + def suspend | ||
| 96 | + authenticate | ||
| 97 | + @question = current_user.questions.find(params[:question_id]) | ||
| 98 | + @choice = @question.choices.find(params[:id]) | ||
| 99 | + respond_to do |format| | ||
| 100 | + if @choice.suspend! | ||
| 101 | + format.xml { render :xml => @choice.to_xml, :status => :created } | ||
| 102 | + format.json { render :json => @choice.to_json, :status => :created } | ||
| 103 | + else | ||
| 104 | + format.xml { render :xml => @choice.errors, :status => :unprocessable_entity } | ||
| 105 | + format.json { render :json => @choice.to_json } | ||
| 106 | + end | ||
| 107 | + end | ||
| 108 | + end | ||
| 60 | 109 | ||
| 61 | 110 | ||
| 62 | def skip | 111 | def skip |
app/models/choice.rb
| 1 | class Choice < ActiveRecord::Base | 1 | class Choice < ActiveRecord::Base |
| 2 | + include Activation | ||
| 3 | + | ||
| 2 | belongs_to :question | 4 | belongs_to :question |
| 3 | belongs_to :item | 5 | belongs_to :item |
| 4 | belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" | 6 | belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" |