mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
89 lines
2.2 KiB
Ruby
89 lines
2.2 KiB
Ruby
class CategoriesController < ApplicationController
|
|
layout "photos"
|
|
# GET /categories
|
|
# GET /categories.xml
|
|
def index
|
|
@categories = Category.paginate :all, :page => params[:page], :per_page => 4
|
|
|
|
@num_categories = @categories.count
|
|
|
|
@photos = Photo.all(:limit => 2, :order => 'RANDOM()', :conditions => { :featured => true })
|
|
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.xml { render :xml => @categories }
|
|
end
|
|
end
|
|
|
|
# GET /categories/1
|
|
# GET /categories/1.xml
|
|
def show
|
|
@category = Category.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.xml { render :xml => @category }
|
|
end
|
|
end
|
|
|
|
# GET /categories/new
|
|
# GET /categories/new.xml
|
|
def new
|
|
@category = Category.new
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.xml { render :xml => @category }
|
|
end
|
|
end
|
|
|
|
# GET /categories/1/edit
|
|
def edit
|
|
@category = Category.find(params[:id])
|
|
end
|
|
|
|
# POST /categories
|
|
# POST /categories.xml
|
|
def create
|
|
@category = Category.new(params[:category])
|
|
|
|
respond_to do |format|
|
|
if @category.save
|
|
format.html { redirect_to(@category, :notice => 'Category was successfully created.') }
|
|
format.xml { render :xml => @category, :status => :created, :location => @category }
|
|
else
|
|
format.html { render :action => "new" }
|
|
format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PUT /categories/1
|
|
# PUT /categories/1.xml
|
|
def update
|
|
@category = Category.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
if @category.update_attributes(params[:category])
|
|
format.html { redirect_to(@category, :notice => 'Category was successfully updated.') }
|
|
format.xml { head :ok }
|
|
else
|
|
format.html { render :action => "edit" }
|
|
format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /categories/1
|
|
# DELETE /categories/1.xml
|
|
def destroy
|
|
@category = Category.find(params[:id])
|
|
@category.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to(categories_url) }
|
|
format.xml { head :ok }
|
|
end
|
|
end
|
|
end
|