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

class Admin::TimelineContentsController < ApplicationController
  layout "admin"
  before_action :auth_admin

  def index
    @timeline_contents = TimelineContent.all

   
  end

  def show
    @timeline_content = TimelineContent.find(params[:id])

  end

  def new
    
    
		@timeline_content = TimelineContent.new(:timeline_year_id => params[:timeline_year_id])
    

  end

 

  def edit
  
    
    @timeline_content = TimelineContent.find(params[:id])
  end

  def create
    @timeline_content = TimelineContent.new(params.require(:timeline_content).permit!)


    if @timeline_content.save
     redirect_to admin_timeline_history_url(@timeline_content.timeline_year.timeline_history.id), notice: 'Lannée a été crée.' 
      
    else
      render action: "new"
 
    end

  end


  def update
    @timeline_content = TimelineContent.find(params[:id])


    if @timeline_content.update_attributes(params.require(:timeline_content).permit!)
      redirect_to admin_timeline_history_url(@timeline_content.timeline_year.timeline_history.id), notice: 'Lannée a été crée.'  
     
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @timeline_content = TimelineContent.find(params[:id])
    @timeline_content.destroy
    
    #redirect_to admin_timeline_contents_url

  end
end
