def admin_add
      return unless user_is_allowed('categories', 'add')
      
      if params[:parent_id].nil? or params[:parent_id].empty?
        render :json => { :error => 'Please select a parent category.' }
      elsif params[:name].nil? or params[:name].empty?
        render :json => { :error => 'This title cannot be empty' }
      else
        category           = Category.new
        category.parent_id = params[:parent_id]
        category.name      = params[:name]
        category.slug      = category.generate_slug
        category.url       = "#{Category.find(params[:parent_id]).url}/#{category.slug}"
        
        if category.save
          render :json => { :success => true, :redirect => "/admin/categories/#{category.id}/edit" }
        else
          render :json => { :error => 'There was an error saving the category.' }
        end
      end
    end
def admin_add
      return unless user_is_allowed('categories', 'add')
      
      if params[:parent_id].nil? or params[:parent_id].empty?
        render :json => { :error => 'Please select a parent category.' }
      elsif params[:name].nil? or params[:name].empty?
        render :json => { :error => 'This title cannot be empty' }
      else
        category           = Category.new
        category.parent_id = params[:parent_id]
        category.name      = params[:name]
        category.slug      = category.generate_slug
        category.url       = "#{Category.find(params[:parent_id]).url}/#{category.slug}"
        
        if category.save
          render :json => { :success => true, :redirect => "/admin/categories/#{category.id}/edit" }
        else
          render :json => { :error => 'There was an error saving the category.' }
        end
      end
    end
POST /admin/categories