app/controllers/questionnaires_controller.rb
# Zhewei: This method is used to save all questions in current questionnaire.
This method is used to save all questions in current questionnaire.
This method is used to save all questions in current questionnaire .
def save_all_questions
    questionnaire_id = params[:id]
    begin
      if params[:save]
        params[:question].each_pair do |k, v|
          @question = Question.find(k)
          v.each_pair do |key, value|
            @question.send(key + '=', value) if @question.send(key) != value
          end
          @question.save
          flash[:success] = 'All questions has been successfully saved!'
        end
      end
    rescue StandardError
      flash[:error] = $ERROR_INFO
    end
    export if params[:export]
    import if params[:import]
    if params[:view_advice]
      redirect_to controller: 'advice', action: 'edit_advice', id: params[:id]
    elsif !questionnaire_id.nil?
      redirect_to edit_questionnaire_path(questionnaire_id.to_sym)
    end
  end
def save_all_questions questionnaire_id = params [ :id ] begin if params [ :save ] params [ :question ] . each_pair do | k , v | @question = Question . find ( k ) v . each_pair do | key , value | @question . send ( key + '=' , value ) if @question . send ( key ) != value end @question . save flash [ :success ] = 'All questions has been successfully saved!' end end rescue StandardError flash [ :error ] = $ERROR_INFO end export if params [ :export ] import if params [ :import ] if params [ :view_advice ] redirect_to controller : 'advice' , action : 'edit_advice' , id : params [ :id ] elsif ! questionnaire_id . nil? redirect_to edit_questionnaire_path ( questionnaire_id . to_sym ) end end
Zhewei: This method is used to save all questions in current questionnaire.
Zhewei : This method is used to save all questions in current questionnaire .
# example of 'v' value # {"seq"=>"1.0", "txt"=>"WOW", "weight"=>"1", "size"=>"50,3", "max_label"=>"Strong agree", "min_label"=>"Not agree"}