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

class Public::PFriendsController < ApplicationController
  layout "public"
  before_filter :auth_p_customer


  def index
    @p_friends = current_p_customer.p_friends.order(:name).all

   
  end

  def show
    @p_friend = current_p_customer.p_friends.find(params[:id])

  end

  def new
    
    
		@p_friend = current_p_customer.p_friends.new
    

  end

 
  def confirm
    @p_friend = PFriend.where(:p_friend_customer_id => current_p_customer.id).find(params[:id])
    @p_friend.confirm
    
    redirect_to :back
  end

  def edit
  
    
    @p_friend = current_p_customer.p_friends.find(params[:id])
  end

  def create
    @p_friend = current_p_customer.p_friends.new(params.require(:p_friend).permit!)
    
    
    @p_friend.initiator = true
    
    if @p_friend.save
     @p_friends = current_p_customer.p_friends.order(:name).all
      
    else
      render action: "new"
 
    end

  end


  def update
    @p_friend = current_p_customer.p_friends.find(params[:id])


    if @p_friend.update_attributes(params.require(:p_friend).permit!)
      
       @p_friends = current_p_customer.p_friends.order(:name).all
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @p_friend = current_p_customer.p_friends.find(params[:id])
    @p_friend.destroy
    
    
  end
end
