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