Class: Mg::TestsController

Inherits:
Mg
  • Object
show all
Defined in:
lib/mountain-goat/controllers/mg/tests_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

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

#destroyObject

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

#editObject

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_choicesObject

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']}"
  
  cookies.each do |cookie|
    if cookie[0] =~ /test_([a-z0-9_]+)/
      logger.warn "Deleting cookie #{cookie[0]}"
      cookies.delete cookie[0]
    end
  end
  
  flash[:notice] = "Your tests have been cleared from cookies."
  redirect_to :back
end

#hideObject

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

#indexObject

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

#newObject

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

#showObject

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

#unhideObject

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

#updateObject

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