orbit-basic/app/controllers/admin/announcements_controller.rb

70 lines
1.9 KiB
Ruby
Raw Normal View History

class Admin::AnnouncementsController < ApplicationController
2010-01-11 09:09:50 +00:00
before_filter :require_entry_name, :only => [:index, :new]
layout "admin"
def index
2010-01-11 09:09:50 +00:00
@announcements = Announcement.find(:all, :conditions => { :entry_name => params[:entry_name] })
respond_to do |format|
2010-01-11 09:09:50 +00:00
format.html
format.xml { render :xml => @announcements }
end
end
def new
@announcement = Announcement.new
2010-01-11 09:09:50 +00:00
@announcement.entry_name = params[:entry_name]
respond_to do |format|
2010-01-11 09:09:50 +00:00
format.htm
format.xml { render :xml => @announcement }
end
end
def edit
@announcement = Announcement.find(params[:id])
end
def create
@announcement = Announcement.new(params[:announcement])
2010-01-11 09:09:50 +00:00
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