# -*- encoding : utf-8 -*-
class TopicsController < ApplicationController
  before_filter :authenticate_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[:topic])
    @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[:topic])
      @topics = Topic.all
    else
       render :action => :edit 
    end
    
  end

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