Class: Mg::TestsController
- Defined in:
- lib/mountain-goat/controllers/mg/tests_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /mg/tests POST /mg/tests.xml.
-
#destroy ⇒ Object
DELETE /mg/tests/1 DELETE /mg/tests/1.xml.
-
#edit ⇒ Object
GET /mg/tests/1/edit.
-
#fresh_choices ⇒ Object
TODO: This only works if we are using cookie storage? Clear session as well.
-
#hide ⇒ Object
GET /mg/tests/1/hide GET /mg/tests/1/hide.xml.
-
#index ⇒ Object
GET /mg/tests GET /mg/tests.xml.
-
#new ⇒ Object
GET /mg/tests/new GET /mg/tests/new.xml.
-
#show ⇒ Object
TODO: Whhhhha? GET /mg/tests/1 GET /mg/tests/1.xml.
-
#unhide ⇒ Object
GET /mg/tests/1/unhide GET /mg/tests/1/unhide.xml.
-
#update ⇒ Object
PUT /mg/tests/1 PUT /mg/tests/1.xml.
Instance Method Details
#create ⇒ Object
POST /mg/tests POST /mg/tests.xml
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 46 def create @test = Mg::Test.new(params[:test]) if @test.save flash[:notice] = 'Test was successfully created.' redirect_to mg_test_url :id => @test.id else render :action => "new" end end |
#destroy ⇒ Object
DELETE /mg/tests/1 DELETE /mg/tests/1.xml
98 99 100 101 102 103 104 105 106 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 98 def destroy @test = Mg::Test.find(params[:id]) @test.destroy respond_to do |format| format.html { redirect_to(mg_tests_url) } format.xml { head :ok } end end |
#edit ⇒ Object
GET /mg/tests/1/edit
40 41 42 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 40 def edit @test = Mg::Test.find(params[:id]) end |
#fresh_choices ⇒ Object
TODO: This only works if we are using cookie storage? Clear session as well
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 109 def fresh_choices #clear choices #logger.warn "Headerish #{response.headers['cookie']}" .each do || if [0] =~ /test_([a-z0-9_]+)/ logger.warn "Deleting cookie #{[0]}" .delete [0] end end flash[:notice] = "Your tests have been cleared from cookies." redirect_to :back end |
#hide ⇒ Object
GET /mg/tests/1/hide GET /mg/tests/1/hide.xml
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 72 def hide @test = Mg::Test.find(params[:id]) @test.update_attribute(:is_hidden, true) flash[:notice] = "Test #{@test.title} has been hidden." respond_to do |format| format.html { redirect_to mg_tests_url } format.xml { head :ok } end end |
#index ⇒ Object
GET /mg/tests GET /mg/tests.xml
6 7 8 9 10 11 12 13 14 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 6 def index @tests = Mg::Test.all(:conditions => { :is_hidden => false } ) @hidden_tests = Mg::Test.all(:conditions => { :is_hidden => true } ) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @tests } end end |
#new ⇒ Object
GET /mg/tests/new GET /mg/tests/new.xml
30 31 32 33 34 35 36 37 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 30 def new @test = Mg::Test.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @test } end end |
#show ⇒ Object
TODO: Whhhhha? GET /mg/tests/1 GET /mg/tests/1.xml
19 20 21 22 23 24 25 26 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 19 def show @test = Mg::Test.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @test } end end |
#unhide ⇒ Object
GET /mg/tests/1/unhide GET /mg/tests/1/unhide.xml
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 85 def unhide @test = Mg::Test.find(params[:id]) @test.update_attribute(:is_hidden, false) flash[:notice] = "Test #{@test.title} has been restored." respond_to do |format| format.html { redirect_to mg_tests_url } format.xml { head :ok } end end |
#update ⇒ Object
PUT /mg/tests/1 PUT /mg/tests/1.xml
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mountain-goat/controllers/mg/tests_controller.rb', line 59 def update @test = Mg::Test.find(params[:id]) if @test.update_attributes(params[:test]) flash[:notice] = 'Test was successfully updated.' redirect_to mg_test_url :id => @test.id else render :action => "edit" end end |