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

class Public::KapsmesController < ApplicationController
  layout "public"
  before_filter :auth_p_customer
  skip_before_action :update

  def index
    @kapsmes = Kapsme.order(:name).all

   
  end

  def show
    @kapsme = Kapsme.find(params[:id])

  end

  def new
    
    
		@kapsme = Kapsme.new
    

  end

 

  def edit
  
    
    @kapsme = Kapsme.find(params[:id])
  end

  def create
    @kapsme = Kapsme.new(params.require(:kapsme).permit!)
    @kapsme.p_customer = current_p_customer

    if @kapsme.save
     @kapsmes = Kapsme.order(:name).all
      
    else
      render action: "new"
 
    end

  end


  def update
    @kapsme = Kapsme.find(params[:id])


    if @kapsme.update_attributes(params.require(:kapsme).permit!)
      
      @kaps_day = @kapsme.kaps_day
      
      @kapsmes = Kapsme.order(:name).all
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @kapsme = Kapsme.find(params[:id])
    @kapsme.destroy
    
    
  end
end
