class Admin::PagesController

Admin editing for Pages in built-in CMS. All editing actions expire the cache.

Public Instance Methods

create() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 15
def create
  @page = Page.new(params["page"])
  @page.save
  if @page.errors.empty?
    flash[:notice] = "Created #{@page.title}"
    expire_cache
    redirect_to(edit_admin_page_path(@page))
  else
    render :edit
  end
end
destroy() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 54
def destroy
  @page = Page.find(params[:id])
  begin
    ActiveRecord::Base.lock_optimistically = false
    @page.destroy
  ensure
    ActiveRecord::Base.lock_optimistically = true
  end
  
  expire_cache
  flash[:notice] = "Deleted #{@page.title}"
  redirect_to admin_pages_path
end
edit() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 27
def edit
  @page = Page.find(params[:id])
end
index() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 6
def index
  @pages = Page.roots
end
new() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 10
def new
  @page = Page.new(params[:page])
  render :edit
end
update() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 31
def update
  @page = Page.find(params[:id])
  if @page.update_attributes(params[:page])
    flash[:notice] = "Updated #{@page.title}"
    expire_cache
    redirect_to(edit_admin_page_path(@page))
  else
    render :edit
  end
end
update_attribute() click to toggle source
# File app/controllers/admin/pages_controller.rb, line 42
def update_attribute
  respond_to do |format|
    format.js {
      @page = Page.find(params[:id])
      @page.send "#{params[:name]}=", params[:value]
      @page.save!
      expire_cache
      render :text => @page.send(params[:name]), :content_type => "text/html"
    }
  end
end