Class: SurveyAnswersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SurveyAnswersController
- Defined in:
- app/controllers/survey_answers_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/survey_answers_controller.rb', line 20 def create @survey = Survey.find(params[:survey_id]) params[:answers].each do |f| @survey_answer = SurveyAnswer.new(:question_id=>f[0], :answer_id=>f[1], :user_id=>current_user.id, :survey_id=>@survey.id) if (@survey_answer.save) else @survey_answer = SurveyAnswer.where(:question_id=>f[0], :user_id=>current_user.id).first @survey_answer.answer_id = f[1] @survey_answer.save end end redirect_to survey_results_path(@survey) end |
#destroy ⇒ Object
49 50 51 52 53 54 |
# File 'app/controllers/survey_answers_controller.rb', line 49 def destroy @survey = Survey.find(params[:id]) @survey.destroy flash[:notice] = "Successfully destroyed survey." redirect_to surveys_url end |
#edit ⇒ Object
35 36 37 |
# File 'app/controllers/survey_answers_controller.rb', line 35 def edit @survey = Survey.find(params[:id]) end |
#index ⇒ Object
2 3 4 |
# File 'app/controllers/survey_answers_controller.rb', line 2 def index @surveys = Survey.all end |
#new ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/controllers/survey_answers_controller.rb', line 12 def new @survey = Survey.new 3.times do question = @survey.questions.build 4.times { question.answers.build } end end |
#show ⇒ Object
6 7 8 9 10 |
# File 'app/controllers/survey_answers_controller.rb', line 6 def show authenticate_user! @survey = Survey.find(params[:id]) @survey_answer = SurveyAnswer.new end |
#update ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/survey_answers_controller.rb', line 39 def update @survey = Survey.find(params[:id]) if @survey.update_attributes(params[:survey]) flash[:notice] = "Successfully updated survey." redirect_to @survey else render :action => 'edit' end end |