<commit_before>class QuestionnairesController < ResourceController::Base
  belongs_to :research
  before_filter :load_research

  def new

    @questionnaire = Questionnaire.new

    if params[:commit].nil?
     # @page = 1
       @page = 0
    elsif /back/i =~ params[:commit]
      @page = params[:page_id].to_i - 1
    elsif /next/i =~ params[:commit] or /submit/i =~ params[:commit]
      @page = params[:page_id].to_i + 1
    end 
    flash[:answers] ||= {}  
    #FIXME create a method called invalid? that evaluates the result
    flash[:answers] = flash[:answers].merge(params[:object_item_values]) unless params[:object_item_values].nil?

    @current_items = @research.questions.find_all { |i| i.page_id == @research.page_ids[@page] }
   if request.post? and /submit/i =~ params[:commit]
      create
    end 
  end

  def create
    @questionnaire = Questionnaire.new
    saved = @questionnaire.prepare_to_save(flash[:answers], params[:public_id].to_i)
    if not saved or not @questionnaire.save
      render :action => 'new'
    else
      flash[:notice] = t(:succesfully_saved)
      redirect_to public_url(params[:public_id].to_i)
    end
  end

end<commit_msg>Fixing cache bug on questionnaires<commit_after>class QuestionnairesController < ResourceController::Base
  belongs_to :research
  before_filter :load_research

    require 'pp'
  def new
    pp flash[:answers]
    @questionnaire = Questionnaire.new

    if params[:commit].nil?
       @page = 0
    elsif /back/i =~ params[:commit]
      @page = params[:page_id].to_i - 1
    elsif /next/i =~ params[:commit]      
      @page = params[:page_id].to_i + 1  
    elsif /submit/i =~ params[:commit]
      @page = params[:page_id].to_i
    end 
    flash[:answers] ||= {}  
    #FIXME create a method called invalid? that evaluates the result
    flash[:answers] = flash[:answers].merge(params[:object_item_values]) unless params[:object_item_values].nil?
    pp 'flash'
    pp flash[:answers]


    @current_items = @research.questions.find_all { |i| i.page_id == @research.page_ids[@page] }
   if request.post? and /submit/i =~ params[:commit]
      create
    end 
  end

  def create
    @questionnaire = Questionnaire.new
    saved = @questionnaire.prepare_to_save(flash[:answers], params[:public_id].to_i)
    if not saved or not @questionnaire.save
      flash[:answers] = flash[:answers]
      render :action => 'new'
    else
      flash[:notice] = t(:succesfully_saved)
      redirect_to public_url(params[:public_id].to_i)
    end
  end

end
{'fraction_non_alphanumeric': 0.12356435643564356, 'fraction_numerical': 0.002772277227722772, 'mean_word_length': 3.3327615780445967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923542', 'n_tokens_mistral': 860, 'n_tokens_neox': 808, 'n_words': 183}