# -*- encoding : utf-8 -*-
class Admin::TopicsController < ApplicationController
 before_filter :auth_admin


layout "admin"

  def index
    @topics = Topic.all

  end

  def show
    @topic = Topic.find(params[:id])

  end

  
  def new
    @topic = Topic.new

  end

  
  def edit
    @topic = Topic.find(params[:id])
  end

  def create
    @topic = Topic.new(params.require(:topic).permit!)
    @topic.admin = current_admin
    
    if @topic.save
      @topics = Topic.all
    else
      @topic_create = true
       render :action => :new
    end

  end

  def update
    @topic = Topic.find(params[:id])

   
    if @topic.update_attributes(params.require(:topic).permit!)
      @topics = Topic.all
    else
       render :action => :edit 
    end
    
  end

  def destroy
    @topic = Topic.find(params[:id])
    @topic.destroy
  end
  
end