<commit_before>class Admin::ContentElementsController < ApplicationController
  
  # GET /admin/pages/:page_id/content_elements/new                        AJAX
  #----------------------------------------------------------------------------
  def new
    @content_element = ContentElement.new
    
    render :update do |page|
      page['middle_content'].replace_html :partial => "new"
    end
  end
  
  # POST /admin/pages/:page_id/content_elements/                            AJAX
  #-----------------------------------------------------------------------------
  def create
    @content_element = ContentElement.new(params[:content_element])
    @content_element.from_content_element params[:page_id], params[:content_element_id]
    
    if @content_element.save
      @content_element.create_element_type
      @partial_file = "admin/pages/show"
      @page = Page.find(params[:page_id])
      @content_elements = @page.content_elements.sorted
    else
      @partial_file = "new"
    end
    
    render :update do |page|
      page['notifications'].replace_html render_notifications
      page['middle_content'].replace_html :partial => @partial_file
    end
  end
  
  # GET /admin/pages/:page_id/content_elements/:id/edit                     AJAX
  #-----------------------------------------------------------------------------
  def edit
    @content_element = ContentElement.find(params[:id])
    @page = @content_element.page
    render :update do |page|
      page['middle_content'].replace_html :partial => "edit"
    end
  end
  
  # PUT /admin/pages/:page_id/content_elements/:id                         AJAX
  #-----------------------------------------------------------------------------
  def update
    @content_element = ContentElement.find(params[:id])
    if @content_element.update_attributes(params[:content_element]) && Kernel.const_get(@content_element.element_type).find_by_content_element_id(params[:id]).update_attributes(params[:type])
      flash[:notice] = 'changes_saved_succesfully'
      # redirect to reload locales
    else
      flash.now[:error] = 'check_your_input'
    end
    @page = @content_element.page
    @content_elements = @page.content_elements<commit_msg>fixed a bug in the if condition<commit_after>class Admin::ContentElementsController < ApplicationController
  
  # GET /admin/pages/:page_id/content_elements/new                        AJAX
  #----------------------------------------------------------------------------
  def new
    @content_element = ContentElement.new
    
    render :update do |page|
      page['middle_content'].replace_html :partial => "new"
    end
  end
  
  # POST /admin/pages/:page_id/content_elements/                            AJAX
  #-----------------------------------------------------------------------------
  def create
    @content_element = ContentElement.new(params[:content_element])
    @content_element.from_content_element params[:page_id], params[:content_element_id]
    
    if @content_element.save
      @content_element.create_element_type
      @partial_file = "admin/pages/show"
      @page = Page.find(params[:page_id])
      @content_elements = @page.content_elements.sorted
    else
      @partial_file = "new"
    end
    
    render :update do |page|
      page['notifications'].replace_html render_notifications
      page['middle_content'].replace_html :partial => @partial_file
    end
  end
  
  # GET /admin/pages/:page_id/content_elements/:id/edit                     AJAX
  #-----------------------------------------------------------------------------
  def edit
    @content_element = ContentElement.find(params[:id])
    @page = @content_element.page
    render :update do |page|
      page['middle_content'].replace_html :partial => "edit"
    end
  end
  
  # PUT /admin/pages/:page_id/content_elements/:id                         AJAX
  #-----------------------------------------------------------------------------
  def update
    @content_element = ContentElement.find(params[:id])
    if @content_element.update_attributes(params[:content_element]) && 
      (@content_element.element_type=="ContentElement" || Kernel.const_get(@content_element.element_type).find_by_content_element_id(params[:id]).update_attributes(params[:type]))
      flash[:notice] = 'changes_saved_succesfully'
      # redirect to reload locales
    else
      flash.now[:error] = 'check_your_input'
    end
    @page = @content_element.page
    @content_elements = @page.content_elements
{'fraction_non_alphanumeric': 0.22741433021806853, 'fraction_numerical': 0.0, 'mean_word_length': 1.861234882240611, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7553098', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1168, 'n_words': 196}