|
Get Control
Listing 2. You can use the rails framework's scaffold generator to create this controller class. class CatalogsController < ApplicationController
def index
list
render :action => 'list'
end
# GETs should be safe (see
# http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy,
:create, :update ], :redirect_to => {
:action => :list }
def list
@catalog_pages, @catalogs = paginate :catalogs,
:per_page => 10
end
def show
@catalog = Catalog.find(params[:id])
end
def new
@catalog = Catalog.new
end
def create
@catalog = Catalog.new(params[:catalog])
if @catalog.save
flash[:notice] =
'Catalog was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@catalog = Catalog.find(params[:id])
end
def update
@catalog = Catalog.find(params[:id])
if @catalog.update_attributes(params[:catalog])
flash[:notice] =
'Catalog was successfully updated.'
redirect_to :action => 'show', :id => @catalog
else
render :action => 'edit'
end
end
def destroy
Catalog.find(params[:id]).destroy
redirect_to :action => 'list'
end
end
|