Class: SurveysController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/surveys_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /surveys POST /surveys.xml



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/surveys_controller.rb', line 43

def create
  @survey = Survey.new(params[:survey])

  respond_to do |format|
    if @survey.save
      flash[:notice] = 'Survey was successfully created.'
      format.html { redirect_to(@survey) }
      format.xml  { render :xml => @survey, :status => :created, :location => @survey }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @survey.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /surveys/1 DELETE /surveys/1.xml



77
78
79
80
81
82
83
84
85
# File 'app/controllers/surveys_controller.rb', line 77

def destroy
  @survey = Survey.find(params[:id])
  @survey.destroy

  respond_to do |format|
    format.html { redirect_to(surveys_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /surveys/1/edit



37
38
39
# File 'app/controllers/surveys_controller.rb', line 37

def edit
  @survey = Survey.find(params[:id])
end

#indexObject

GET /surveys.xml



5
6
7
8
9
10
11
12
# File 'app/controllers/surveys_controller.rb', line 5

def index
  @surveys = Survey.find(:all)

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

#newObject

GET /surveys/new GET /surveys/new.xml



27
28
29
30
31
32
33
34
# File 'app/controllers/surveys_controller.rb', line 27

def new
  @survey = Survey.new

  respond_to do |format|
    format.html # new.html.haml
    format.xml  { render :xml => @survey }
  end
end

#showObject

GET /surveys/1 GET /surveys/1.xml



16
17
18
19
20
21
22
23
# File 'app/controllers/surveys_controller.rb', line 16

def show
  @survey = Survey.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @survey.to_xml(:include => :sections) }
  end
end

#updateObject

PUT /surveys/1 PUT /surveys/1.xml



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/surveys_controller.rb', line 60

def update
  @survey = Survey.find(params[:id])

  respond_to do |format|
    if @survey.update_attributes(params[:survey])
      flash[:notice] = 'Survey was successfully updated.'
      format.html { redirect_to(@survey) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @survey.errors, :status => :unprocessable_entity }
    end
  end
end