Class: Rapidfire::SurveysController
Instance Method Summary
collapse
#authenticate_administrator!, #rapidfire_scoped
Instance Method Details
#create ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 15
def create
source_survey = nil
if params[:copy_survey_id]
source_survey = Rapidfire::Survey.find(params[:copy_survey_id])
params[:survey] = source_survey.attributes.except(*%w(created_at updated_at id))
params[:survey][:name] = "Copy of #{params[:survey][:name]}"
end
@survey = Rapidfire::Survey.new(survey_params)
if source_survey
source_survey.questions.each do |q|
@survey.questions << q.dup
end
end
if @survey.save
respond_to do |format|
format.html { redirect_to surveys_path }
format.js
end
else
respond_to do |format|
format.html { render :new }
format.js
end
end
end
|
#destroy ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 62
def destroy
@survey = Rapidfire::Survey.find(params[:id])
@survey.destroy
respond_to do |format|
format.html { redirect_to surveys_path }
format.js
end
end
|
#edit ⇒ Object
43
44
45
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 43
def edit
@survey = Rapidfire::Survey.find(params[:id])
end
|
#index ⇒ Object
5
6
7
8
9
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 5
def index
@surveys = Rapidfire::Survey.all
@surveys = @surveys.page(params[:page]) if defined?(Kaminari)
@surveys
end
|
#new ⇒ Object
11
12
13
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 11
def new
@survey = Rapidfire::Survey.new
end
|
#results ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 72
def results
params[:filter] ||= {}
@survey = Rapidfire::Survey.find(params[:id])
@survey_results =
SurveyResults.new(survey: @survey).(filter_params)
respond_to do |format|
format.json { render json: @survey_results, root: false }
format.html
format.js
format.csv { send_data(@survey.results_to_csv(filter_params)) }
end
end
|
#update ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/rapidfire/surveys_controller.rb', line 47
def update
@survey = Rapidfire::Survey.find(params[:id])
if @survey.update(survey_params)
respond_to do |format|
format.html { redirect_to surveys_path }
format.js
end
else
respond_to do |format|
format.html { render :edit }
format.js
end
end
end
|