2007-09-27 02:19:14 -04:00
|
|
|
class PagesController < ApplicationController
|
2008-01-02 02:58:03 -05:00
|
|
|
append_before_filter :fetch_model,
|
|
|
|
:only => [ :show, :edit, :update, :destroy ]
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# GET /pages
|
|
|
|
# GET /pages.xml
|
|
|
|
def index
|
2008-01-02 02:58:03 -05:00
|
|
|
@page = Page.find_by_title_and_owner_type 'HomePage', nil
|
2007-10-03 02:34:21 -04:00
|
|
|
@page ||= Page.create :title => 'HomePage',
|
|
|
|
:redcloth => 'Welcome to BarleySodas!'
|
2007-11-17 04:42:02 -05:00
|
|
|
@content_title = 'The Beer Wiki'
|
|
|
|
@secondary_title = 'Browsing all pages'
|
|
|
|
|
|
|
|
cond_ary = [ 'owner_id IS NULL' ]
|
|
|
|
cond_ary << "title <> 'HomePage'"
|
2008-01-16 11:31:57 -05:00
|
|
|
@pages, @wiki_pages = paginate :page, :per_page => per_page,
|
2007-11-17 04:42:02 -05:00
|
|
|
:order => 'title ASC', :conditions => [ cond_ary.join(' AND ') ]
|
|
|
|
|
2008-01-02 02:58:03 -05:00
|
|
|
@tags = Page.tags(:limit => 25, :order => "name ASC")
|
2007-11-28 02:16:41 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.rhtml
|
|
|
|
end
|
|
|
|
end
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# 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
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# GET /pages/new
|
|
|
|
def new
|
|
|
|
@page = Page.new
|
2008-01-02 02:58:03 -05:00
|
|
|
@page.title = params[:new_title] if params[:new_title]
|
2007-10-03 02:34:21 -04:00
|
|
|
end
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# GET /pages/1;edit
|
|
|
|
def edit
|
|
|
|
end
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# POST /pages
|
|
|
|
# POST /pages.xml
|
|
|
|
def create
|
|
|
|
@page = Page.new params[:page]
|
2007-11-28 01:17:25 -05:00
|
|
|
allow_page_discussions
|
2007-10-03 02:34:21 -04:00
|
|
|
respond_to do |format|
|
|
|
|
if @page.save
|
|
|
|
flash[:notice] = 'Page was successfully created.'
|
2007-11-11 01:19:15 -05:00
|
|
|
format.html { redirect_to page_url({ :id => @page.title_for_url }) }
|
|
|
|
format.xml { head :created,
|
|
|
|
:location => page_url({ :id => @page.title_for_url }) }
|
2007-10-03 02:34:21 -04:00
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.xml { render :xml => @page.errors.to_xml }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# PUT /pages/1
|
|
|
|
# PUT /pages/1.xml
|
|
|
|
def update
|
2007-11-17 02:12:34 -05:00
|
|
|
@page.attributes = params[:page]
|
2007-10-03 02:34:21 -04:00
|
|
|
respond_to do |format|
|
2007-11-17 02:12:34 -05:00
|
|
|
if @page.save
|
2007-10-03 02:34:21 -04:00
|
|
|
flash[:notice] = 'Page was successfully updated.'
|
2008-01-02 02:58:03 -05:00
|
|
|
format.html {
|
|
|
|
if @page.title == 'HomePage'
|
|
|
|
redirect_to pages_url
|
|
|
|
else
|
|
|
|
redirect_to page_url({ :id => @page.title_for_url })
|
|
|
|
end
|
|
|
|
}
|
2007-10-03 02:34:21 -04:00
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @page.errors.to_xml }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
# 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
|
2007-11-11 01:19:15 -05:00
|
|
|
|
2007-10-03 02:34:21 -04:00
|
|
|
##
|
|
|
|
# Redirects the user to a default location.
|
|
|
|
#
|
|
|
|
def default_action
|
|
|
|
redirect_to(pages_path)
|
|
|
|
end
|
|
|
|
end
|