Class: SurveyingController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- SurveyingController
show all
- Includes:
- SurveyingHelper, UserManager
- Defined in:
- app/controllers/surveying_controller.rb
Overview
The Surveying controller handles the process of a user taking a survey. It is semi-restful since it does not have a concrete representation model. The “resource” could be considered a survey attempt or survey session. It is actually the union of a user filling out a survey and populating a response set.
Instance Method Summary
collapse
#answer_id_helper, #dependency_explanation_helper, #fields_for_radio, #fields_for_repeater_response, #fields_for_response, #question_help_helper, #question_id_helper, #question_number_helper, #question_text_postfix_helper, #question_text_prefix_helper, #section_id_helper, #section_next_helper, #section_previous_helper, #section_submit_helper, #section_submit_name_helper
#current_user
Instance Method Details
#create ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/surveying_controller.rb', line 27
def create
@survey = Survey.find_by_access_code(params[:survey_code])
unless @survey
flash[:notice] = "Unable to find that survey"
redirect_to(available_surveys_path)
else
@response_set = ResponseSet.new(:survey => @survey, :user_id => 123)
respond_to do |format|
if @response_set.save!
flash[:notice] = 'Survey was successfully created.'
format.html { redirect_to(edit_my_survey_path(:survey_code => @survey.access_code, :response_set_code => @response_set.access_code)) }
else
format.html { redirect_to(available_surveys_path)}
end
end
end
end
|
#edit ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/surveying_controller.rb', line 54
def edit
dependent_hash = dependents(@response_set)
@dependents = dependent_hash[:show]
respond_to do |format|
format.html do
render
end
format.json do
render :json => {:show => dependent_hash[:show].map{|q| question_id_helper(q)}, :hide => dependent_hash[:hide].map{|q| question_id_helper(q)} }.to_json
end
end
end
|
#finish ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'app/controllers/surveying_controller.rb', line 88
def finish
respond_to do |format|
format.html do
flash[:notice] = @response_set.complete! ? "Completed survey" : "Unable to complete survey"
render :action => 'edit'
end
end
end
|
#index ⇒ Object
15
16
17
|
# File 'app/controllers/surveying_controller.rb', line 15
def index
@surveys = Survey.find(:all)
end
|
#new ⇒ Object
19
20
21
22
23
24
25
|
# File 'app/controllers/surveying_controller.rb', line 19
def new
@surveys = Survey.find(:all)
respond_to do |format|
format.html end
end
|
#show ⇒ Object
47
48
49
50
51
52
|
# File 'app/controllers/surveying_controller.rb', line 47
def show
respond_to do |format|
format.html end
end
|
#update ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/surveying_controller.rb', line 68
def update
if params[:responses] or params[:response_groups]
saved = @response_set.update_attributes(:response_attributes => (params[:responses] || {}).dup , :response_group_attributes => (params[:response_groups] || {}).dup) end
respond_to do |format|
format.html do
flash[:notice] = saved ? "Updated survey" : "Unable to update survey" unless saved.nil? redirect_to :action => "edit", :anchor => @anchor, :params => {:section => @section.id}
end
format.json do
dependent_hash = dependents(@response_set)
@dependents = dependent_hash[:show]
render :json => {:show => dependent_hash[:show].map{|q| question_id_helper(q)}, :hide => dependent_hash[:hide].map{|q| question_id_helper(q)} }.to_json
end
end
end
|