Class: Rapidfire::SurveysController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_administrator!, #scoped

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/rapidfire/surveys_controller.rb', line 17

def create
  @survey = Survey.new(survey_params)
  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

#destroyObject



51
52
53
54
55
56
57
58
59
# File 'app/controllers/rapidfire/surveys_controller.rb', line 51

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

  respond_to do |format|
    format.html { redirect_to surveys_path }
    format.js
  end
end

#editObject



32
33
34
# File 'app/controllers/rapidfire/surveys_controller.rb', line 32

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

#indexObject



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

def index
  @surveys = if defined?(Kaminari)
    Survey.page(params[:page])
  else
    Survey.all
  end
end

#newObject



13
14
15
# File 'app/controllers/rapidfire/surveys_controller.rb', line 13

def new
  @survey = Survey.new
end

#resultsObject



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

def results
  @survey = Survey.find(params[:id])
  @survey_results =
    SurveyResults.new(survey: @survey).extract

  respond_to do |format|
    format.json { render json: @survey_results, root: false }
    format.html
    format.js
  end
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/rapidfire/surveys_controller.rb', line 36

def update
  @survey = 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