2008-06-27 00:13:15 -04:00
|
|
|
class Pages < Application
|
2009-03-21 22:00:59 -04:00
|
|
|
before :logged_in?, :only => [ :new, :edit, :create, :update, :delete ]
|
|
|
|
|
2008-06-27 00:13:15 -04:00
|
|
|
def index
|
|
|
|
@pages = Page.find :all, :order => 'name ASC', :conditions => [ 'published = ?', false ]
|
|
|
|
@secondary_title = 'Wiki Pages. En Masse.'
|
|
|
|
@tags = Page.popular_tags(30)
|
|
|
|
display @pages
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@page = Page.find_by_name(params[:id].gsub(/_/, ' '))
|
2009-03-21 22:00:59 -04:00
|
|
|
if @page.nil? and logged_in?
|
2008-06-27 00:13:15 -04:00
|
|
|
redirect url(:new_page, :new_name => params[:id])
|
2009-03-21 22:00:59 -04:00
|
|
|
elsif @page.nil?
|
|
|
|
raise NotFound
|
2008-06-27 00:13:15 -04:00
|
|
|
else
|
|
|
|
@comments = @page.comments
|
|
|
|
@secondary_title = @page.name
|
|
|
|
display @page
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@page_title = 'Make a new page'
|
|
|
|
only_provides :html
|
2008-07-23 05:52:42 -04:00
|
|
|
@page = Page.new :published => true
|
2008-06-27 00:13:15 -04:00
|
|
|
if params[:new_name]
|
2008-06-27 21:28:18 -04:00
|
|
|
flash.now[:error] = 'That page does not exist, but you can create it.'
|
2008-06-27 00:13:15 -04:00
|
|
|
@page.name = params[:new_name].gsub(/_/, ' ')
|
|
|
|
end
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@page_title = 'Update page'
|
|
|
|
only_provides :html
|
|
|
|
@page = Page.find_by_name(params[:id].gsub(/_/, ' '))
|
|
|
|
raise NotFound unless @page
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@page = Page.new(params[:page])
|
|
|
|
if @page.save
|
|
|
|
flash[:notice] = "Great success!"
|
|
|
|
redirect url(:page, :id => @page.name.gsub(/ /, '_'))
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@page = Page.find_by_name(params[:id].gsub(/_/, ' '))
|
|
|
|
raise NotFound unless @page
|
|
|
|
if @page.update_attributes(params[:page])
|
|
|
|
flash[:notice] = "Great success!"
|
|
|
|
redirect url(:page, :id => @page.name.gsub(/ /, '_'))
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete
|
|
|
|
@page = Page.find_by_name(params[:id].gsub(/_/, ' '))
|
|
|
|
raise NotFound unless @page
|
2008-06-27 02:24:12 -04:00
|
|
|
if @page.destroy
|
2008-06-27 00:13:15 -04:00
|
|
|
flash[:notice] = "The page was successfully destroyed."
|
|
|
|
redirect url(:page)
|
|
|
|
else
|
|
|
|
raise BadRequest
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|