app/controllers/questionnaire_answers_controller.rb
# Display a questionnaire to answer to

Display a questionnaire to answer to
Display a questionnaire to answer to
def new
    current_user.came_to_answer_questionnaire
    if current_user.specific_q_and_profile_edit?
      session[:specific_q_id] = params[:questionnaire_id]
      eval current_user.redirect, binding()
      return
    end
    if session[:specific_q_id]
      questionnaire_id = session[:specific_q_id]
      session[:specific_q_id] = nil
      redirect_to new_questionnaire_answer_url(:questionnaire_id => questionnaire_id)
      return
    end
    questionnaire_id =  params[:questionnaire_id]
    begin
      @questionnaire = Questionnaire.find(questionnaire_id)
    rescue
      session[:alert] = t('questionnaire_answer.controller.no_questionnaire')
      current_user.specific_questionnaire_is_already_answered_or_not_found
      eval current_user.redirect, binding()
      return
    end
    if false 
      session[:alert] = t('questionnaire_answer.controller.already_answered')
      current_user.specific_questionnaire_is_already_answered_or_not_found
      eval current_user.redirect, binding()
      return
    end
    @questionnaire_answer = QuestionnaireAnswer.new
    @questionnaire_answer.author = current_user
    @questionnaire_answer.questionnaire = @questionnaire
    @questionnaire_answer.answers = QuestionnaireAnswer.prepare_answers(@questionnaire)
  end
def new current_user . came_to_answer_questionnaire if current_user . specific_q_and_profile_edit? session [ :specific_q_id ] = params [ :questionnaire_id ] eval current_user . redirect , binding ( ) return end if session [ :specific_q_id ] questionnaire_id = session [ :specific_q_id ] session [ :specific_q_id ] = nil redirect_to new_questionnaire_answer_url ( :questionnaire_id => questionnaire_id ) return end questionnaire_id = params [ :questionnaire_id ] begin @questionnaire = Questionnaire . find ( questionnaire_id ) rescue session [ :alert ] = t ( 'questionnaire_answer.controller.no_questionnaire' ) current_user . specific_questionnaire_is_already_answered_or_not_found eval current_user . redirect , binding ( ) return end if false session [ :alert ] = t ( 'questionnaire_answer.controller.already_answered' ) current_user . specific_questionnaire_is_already_answered_or_not_found eval current_user . redirect , binding ( ) return end @questionnaire_answer = QuestionnaireAnswer . new @questionnaire_answer . author = current_user @questionnaire_answer . questionnaire = @questionnaire @questionnaire_answer . answers = QuestionnaireAnswer . prepare_answers ( @questionnaire ) end
Display a questionnaire to answer to
Display a questionnaire to answer to
# move to state
 # save specific questionnaire id and redirect according to state machine
 # If came with session and without questionniare_id in params than redirect full URL and nullify session
 # Checks if the questionnaire exists. If not it redirects to *Home*
 # State machine event
 #Check whether this questionnaire was already answered
 #!(current_user.is_admin? || current_user.is_moderator?) && @questionnaire.answered_questionnaire?(current_user)
 # State machine event
 # Create a new answers instance to be filled in form
 # For each question we have to create an 'answer' field
