Class: Mg::ChoicesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /mg/tests/:test_id/choices POST /mg/tests/:test_id/choices.xml



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 45

def create
  @test = Mg::Test.find( params[:choice][:mg_test_id] )
  @choice = Mg::Choice.new(params[:choice])

  if @choice.save
    flash[:notice] = 'Choice was successfully created.'
    redirect_to mg_test_url :id => @choice.mg_test.id 
  else
    render :action => "new"
  end
end

#destroyObject

DELETE /mg/choices/1 DELETE /mg/choices/1.xml



72
73
74
75
76
77
78
79
80
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 72

def destroy
  @choice = Mg::Choice.find(params[:id])
  @choice.destroy

  respond_to do |format|
    format.html { redirect_to mg_choices_url }
    format.xml  { head :ok }
  end
end

#editObject

GET /mg/choices/1/edit



39
40
41
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 39

def edit
  @choice = Mg::Choice.find(params[:id])
end

#indexObject

GET /mg/choices GET /mg/choices.xml



6
7
8
9
10
11
12
13
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 6

def index
  @choices = Mg::Choice.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @choices }
  end
end

#newObject

GET /mg/tests/:test_id/choices/new GET /mg/tests/:test_id/choices/new.xml



28
29
30
31
32
33
34
35
36
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 28

def new
  @test = Mg::Test.find( params[:test_id] )
  @choice = Mg::Choice.new( :mg_test_id => @test.id )
  
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @choice }
  end
end

#showObject

GET /mg/choices/1 GET /mg/coihces/1.xml



17
18
19
20
21
22
23
24
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 17

def show
  @choice = Mg::Choice.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @choice }
  end
end

#updateObject

PUT /mg/choices/1 PUT /mg/choices/1.xml



59
60
61
62
63
64
65
66
67
68
# File 'lib/mountain-goat/controllers/mg/choices_controller.rb', line 59

def update
  @choice = Mg::Choice.find(params[:id])

  if @choice.update_attributes(params[:choice])
    flash[:notice] = 'Choice was successfully updated.'
    redirect_to mg_test_url :id => @choice.mg_test.id
  else
    render :action => "edit"
  end
end