module Forum #:nodoc: all
  class RoomsController < ApplicationController
    before_filter :current_person, :only=>[:index]
    respond_to :html, :xml, :json

    def index
      @rooms =  Room.available_to(current_person).page(params[:page])  if current_person
      @rooms ||=[]
    end

    def show
      @room = Room.find_by_title(params[:id].to_s.titleize)
      @topics = @room.topics.includes(:comment_threads, :votes).page(params[:page])
    end

    def new
      @room = Room.new
      respond_with @room
    end

    def edit
      @room = Room.find(params[:id])
    end

    def create
      @room = Room.new(params[:room])
      @room.save
      respond_with @room
    end

    def update
      @room = Room.find(params[:id])
      @room.update_attributes(params[:room])
      respond_with @room
    end

    def destroy
      @room = Room.find(params[:id])
      @room.destroy
      respond_with @room
    end

  end
end
