class ResourcesController < ApplicationController

  def index
    if @category = Category.find(params[:id]) rescue nil
      @resources = Resource.find(:all, :order => "created_at DESC", :conditions => ['category_id LIKE ?', @category])
    else
      @resources = Resource.find(:all, :order => "created_at DESC")
    end
  end

  def new
    @resource = Resource.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @resource }
    end
  end

  def create
    @resource = Resource.new(params[:resource])

    respond_to do |format|
      if @resource.save
        flash[:notice] = 'Location was successfully created.'
        format.html { redirect_to resources_path }
        format.xml  { render :xml => @resource, :status => :created, :location => @resource }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @resource.errors, :status => :unprocessable_entity }
      end
    end
  end

end