git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@16 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2007-11-11 06:19:15 +00:00
parent cdfbabf38b
commit 6b2883d260
1 changed files with 14 additions and 14 deletions

View File

@ -1,19 +1,18 @@
class PagesController < ApplicationController class PagesController < ApplicationController
append_before_filter :fetch_page, :only => [ :show, :edit, :update, :destroy ] append_before_filter :fetch_page, :only => [ :show, :edit, :update, :destroy ]
# GET /pages # GET /pages
# GET /pages.xml # GET /pages.xml
def index def index
@page = Page.find_by_title 'HomePage' @page = Page.find_by_title 'HomePage'
@page ||= Page.create :title => 'HomePage', @page ||= Page.create :title => 'HomePage',
:redcloth => 'Welcome to BarleySodas!' :redcloth => 'Welcome to BarleySodas!'
respond_to do |format| respond_to do |format|
format.html # index.rhtml format.html # index.rhtml
format.xml { render :xml => @page.to_xml } format.xml { render :xml => @page.to_xml }
end end
end end
# GET /pages/1 # GET /pages/1
# GET /pages/1.xml # GET /pages/1.xml
def show def show
@ -22,16 +21,16 @@ class PagesController < ApplicationController
format.xml { render :xml => @page.to_xml } format.xml { render :xml => @page.to_xml }
end end
end end
# GET /pages/new # GET /pages/new
def new def new
@page = Page.new @page = Page.new
end end
# GET /pages/1;edit # GET /pages/1;edit
def edit def edit
end end
# POST /pages # POST /pages
# POST /pages.xml # POST /pages.xml
def create def create
@ -39,22 +38,23 @@ class PagesController < ApplicationController
respond_to do |format| respond_to do |format|
if @page.save if @page.save
flash[:notice] = 'Page was successfully created.' flash[:notice] = 'Page was successfully created.'
format.html { redirect_to page_url(@page) } format.html { redirect_to page_url({ :id => @page.title_for_url }) }
format.xml { head :created, :location => page_url(@page) } format.xml { head :created,
:location => page_url({ :id => @page.title_for_url }) }
else else
format.html { render :action => "new" } format.html { render :action => "new" }
format.xml { render :xml => @page.errors.to_xml } format.xml { render :xml => @page.errors.to_xml }
end end
end end
end end
# PUT /pages/1 # PUT /pages/1
# PUT /pages/1.xml # PUT /pages/1.xml
def update def update
respond_to do |format| respond_to do |format|
if @page.update_attributes(params[:page]) if @page.update_attributes(params[:page])
flash[:notice] = 'Page was successfully updated.' flash[:notice] = 'Page was successfully updated.'
format.html { redirect_to page_url(@page) } format.html { redirect_to page_url({ :id => @page.title_for_url }) }
format.xml { head :ok } format.xml { head :ok }
else else
format.html { render :action => "edit" } format.html { render :action => "edit" }
@ -62,7 +62,7 @@ class PagesController < ApplicationController
end end
end end
end end
# DELETE /pages/1 # DELETE /pages/1
# DELETE /pages/1.xml # DELETE /pages/1.xml
def destroy def destroy
@ -73,16 +73,16 @@ class PagesController < ApplicationController
format.xml { head :ok } format.xml { head :ok }
end end
end end
## ##
# Redirects the user to a default location. # Redirects the user to a default location.
# #
def default_action def default_action
redirect_to(pages_path) redirect_to(pages_path)
end end
protected protected
def fetch_page def fetch_page
@page = Page.find_by_title(Page.title_from_url(params[:id])) @page = Page.find_by_title(Page.title_from_url(params[:id]))
end end