# -*- encoding : utf-8 -*-

class Public::ParticularsController < ApplicationController
  layout "public"
  before_action :order_params
  def index
    @particulars = current_p_customer.particulars.order(:name).all

   
  end

  def show
    @particular = current_p_customer.particulars.find(params[:id])

  end

  def new
    
    
		@particular = current_p_customer.particulars.new
    #@particular.force_validation = true

  end

 

  def edit
  
    
    @particular = current_p_customer.particular
    #@particular.force_validation = true
  end

  def create
    @particular = current_p_customer.particulars.new(params.require(:particular).permit!)


    if @particular.save
      redirect_to public_my_account_path
     
      
    else
      render action: "new"
 
    end

  end


  def update
    @particular = current_p_customer.particulars.find(params[:id])


    if @particular.update_attributes(params.require(:particular).permit!)
      
      redirect_to public_my_account_path

      
      
       
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @particular = Particular.find(params[:id])
    @particular.destroy
    
    redirect_to public_particulars_path
    
    
  end
  
  private
  def order_params
    if params[:order] == "true"
      params[:order] = true
    else
      params[:order] = nil
    end
    
  end
end
