<commit_before>class ContactsController < ApplicationController
  before_action :set_lead, only: [:index, :new, :create]
  before_action :set_contact, only: [:show, :edit, :update, :destroy]

  # GET /contacts
  # GET /contacts.json
  def index
    # @contacts = Contact.all
    @contacts = Contact.page(params[:page])
  end

  # GET /contacts/1
  # GET /contacts/1.json
  def show
  end

  # GET /contacts/new
  def new
    # @contact = Contact.new
    @contact = @lead.contacts.new
    @contact.date_on = Date.today
  end

  # GET /contacts/1/edit
  def edit
  end

  # POST /contacts
  # POST /contacts.json
  def create
    # @contact = Contact.new(contact_params)
    @contact = @lead.contacts.new(contact_params)

    respond_to do |format|
      if @contact.save
        flash[:notice] = success_message(controller_name, action_name)
        format.html { redirect_to @contact.lead }
        format.json { render :show, status: :created, location: @contact.lead }
      else
        format.html { render :new }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /contacts/1
  # PATCH/PUT /contacts/1.json
  def update
    respond_to do |format|
      if @contact.update(contact_params)
        flash[:notice] = success_message(controller_name, action_name)
        format.html { redirect_to @contact.lead }
        format.json { render :show, status: :ok, location: @contact }
      else
        format.html { render :edit }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /contacts/1
  # DELETE /contacts/1.json
  def destroy
    lead = @contact.lead
    @contact.destroy
    respond_to do |format|
      flash[:notice] = success_message(controller_name, action_name)
      format.html { redirect_to lead }
      format.json { head :no_content }
    end
  end


  # GET /leads/1/contacts/export
  def export
    @contacts = Contact.where(lead_id: params[:lead_id])
    send_data(render_to_string, filename: filename_of(Contact, 'csv'), type: 'text/csv')
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_lead
      @lead = Lead.find(params[:lead_id])
    end
    def set_contact
      @contact = Contact.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def contact_params
      params.require(:contact).permit(:date_on, :content, :means, :owner, :lead_id)
    end
end
<commit_msg>Brush up export file name of contact<commit_after>class ContactsController < ApplicationController
  before_action :set_lead, only: [:index, :new, :create, :export]
  before_action :set_contact, only: [:show, :edit, :update, :destroy]

  # GET /contacts
  # GET /contacts.json
  def index
    # @contacts = Contact.all
    @contacts = Contact.page(params[:page])
  end

  # GET /contacts/1
  # GET /contacts/1.json
  def show
  end

  # GET /contacts/new
  def new
    # @contact = Contact.new
    @contact = @lead.contacts.new
    @contact.date_on = Date.today
  end

  # GET /contacts/1/edit
  def edit
  end

  # POST /contacts
  # POST /contacts.json
  def create
    # @contact = Contact.new(contact_params)
    @contact = @lead.contacts.new(contact_params)

    respond_to do |format|
      if @contact.save
        flash[:notice] = success_message(controller_name, action_name)
        format.html { redirect_to @contact.lead }
        format.json { render :show, status: :created, location: @contact.lead }
      else
        format.html { render :new }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /contacts/1
  # PATCH/PUT /contacts/1.json
  def update
    respond_to do |format|
      if @contact.update(contact_params)
        flash[:notice] = success_message(controller_name, action_name)
        format.html { redirect_to @contact.lead }
        format.json { render :show, status: :ok, location: @contact }
      else
        format.html { render :edit }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /contacts/1
  # DELETE /contacts/1.json
  def destroy
    lead = @contact.lead
    @contact.destroy
    respond_to do |format|
      flash[:notice] = success_message(controller_name, action_name)
      format.html { redirect_to lead }
      format.json { head :no_content }
    end
  end


  # GET /leads/1/contacts/export
  def export
    @contacts = Contact.where(lead_id: @lead.id)
    send_data(render_to_string, filename: filename_of(Contact, 'csv', @lead), type: 'text/csv')
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_lead
      @lead = Lead.find(params[:lead_id])
    end
    def set_contact
      @contact = Contact.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def contact_params
      params.require(:contact).permit(:date_on, :content, :means, :owner, :lead_id)
    end
end

{'fraction_non_alphanumeric': 0.10596927863114913, 'fraction_numerical': 0.003111024693758507, 'mean_word_length': 2.879336349924585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3383898', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1631, 'n_words': 424}