Add announcement admin and view template

This commit is contained in:
Wen-Tien Chang committed 2009-06-01 14:20:15 +08:00
1 parent 4807066c68
commit 5570a2dfbf
12 files changed
+145 -115

No files matched your search

@@ -0,0 +1,66 @@
class Admin::AnnouncementsController < ApplicationController
layout "admin"
def index
@announcements = Announcement.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @announcements }
end
end
def new
@announcement = Announcement.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @announcement }
end
end
def edit
@announcement = Announcement.find(params[:id])
end
def create
@announcement = Announcement.new(params[:announcement])
respond_to do |format|
if @announcement.save
flash[:notice] = 'Announcement was successfully created.'
format.html { redirect_to admin_announcements_path }
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
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 admin_announcements_path }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@announcement = Announcement.find(params[:id])
@announcement.destroy
respond_to do |format|
format.html { redirect_to admin_announcements_path }
format.xml { head :ok }
end
end
end
+11 -67
View File
@@ -1,85 +1,29 @@
class AnnouncementsController < ApplicationController
# GET /announcements
# GET /announcements.xml
def index
@announcements = Announcement.all
respond_to do |format|
format.html # index.html.erb
format.html {
@page = Page.find_by_name( 'announcement_index')
@page_options = { "announcements" => @announcements.map{ |a| a.to_liquid } }
render_liquid_page
}
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.html{
@page = Page.find_by_name( 'announcement_show')
@page_options = { 'announcement' => @announcement.to_liquid }
render_liquid_page
}
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
+19 -7
View File
@@ -1,10 +1,22 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
helper :all
protect_from_forgery
filter_parameter_logging :password
Liquid::Template.register_filter(SnippetFilter)
def render_liquid_page
if @page
@layout = @page.layout
@page_options ||= {}
@page_content = Liquid::Template.parse(@page.content).render(@page_options)
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
else
render :text => '404 Not Found'
end
end
end
+10 -8
View File
@@ -1,22 +1,24 @@
class PagesController < ApplicationController
Liquid::Template.register_filter(SnippetFilter)
def index
@page = Page.find_by_name('home')
if @page
render_liquid_page
else
render :text => 'You need a home page'
end
end
def show
@page = Page.find(:first, :conditions => { :name => params[:page_name], :is_published => true })
@page = Page.find_by_name(params[:page_name])
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
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
else
render :text => '404 not found'
render_liquid_page
end
end