Add announcement model

This commit is contained in:
Wen-Tien Chang committed 2009-06-01 10:54:16 +08:00
1 parent 62602940ed
commit 4807066c68
12 files changed
+182 -278

No files matched your search

@@ -0,0 +1,85 @@
class AnnouncementsController < ApplicationController
# GET /announcements
# GET /announcements.xml
def index
@announcements = Announcement.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @announcements }
end
end
# GET /announcements/1
# GET /announcements/1.xml
def show
@announcement = Announcement.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @announcement }
end
end
# GET /announcements/new
# GET /announcements/new.xml
def new
@announcement = Announcement.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @announcement }
end
end
# GET /announcements/1/edit
def edit
@announcement = Announcement.find(params[:id])
end
# POST /announcements
# POST /announcements.xml
def create
@announcement = Announcement.new(params[:announcement])
respond_to do |format|
if @announcement.save
flash[:notice] = 'Announcement was successfully created.'
format.html { redirect_to(@announcement) }
format.xml { render :xml => @announcement, :status => :created, :location => @announcement }
else
format.html { render :action => "new" }
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
end
end
end
# PUT /announcements/1
# PUT /announcements/1.xml
def update
@announcement = Announcement.find(params[:id])
respond_to do |format|
if @announcement.update_attributes(params[:announcement])
flash[:notice] = 'Announcement was successfully updated.'
format.html { redirect_to(@announcement) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /announcements/1
# DELETE /announcements/1.xml
def destroy
@announcement = Announcement.find(params[:id])
@announcement.destroy
respond_to do |format|
format.html { redirect_to(announcements_url) }
format.xml { head :ok }
end
end
end
+4 -1
View File
@@ -5,8 +5,11 @@ class PagesController < ApplicationController
def show
@page = Page.find(:first, :conditions => { :name => params[:page_name], :is_published => true })
if @page && @page.external_link
if @page && !@page.external_link.blank?
redirect_to @page.external_link
elsif @page && @page.use_engine
#model_class = Kernel.const_get( "Announcement" ) # page.use_engine
redirect_to announcements_path
elsif @page
@layout = @page.layout
@page_content = Liquid::Template.parse(@page.content).render