Sha256: e262409f0290c1e508fa9c0df31a60a49f34431d3ffadbd0b4af808917e01434

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

class Admin::PagesController < Admin::MainController
  before_filter :find_page, :except => [:create, :index, :new]
  before_filter :build_page_sections, :only => [:edit]

  def create
    @page = Page.new(params[:page])
    if @page.save
      flash[:success] = "#{@page.name} was successfully added"
      redirect_to admin_page_path(@page)
    else
      flash[:error] = 'There was a problem creating this page'
      render :new
    end
  end

  def destroy
    @page.destroy
    flash[:delete] = 'Your page has been deleted'
    redirect_to admin_pages_path
  end

  def index
    @pages = Page.where(:parent_id => nil).all
  end

  def new
    @page = Page.new
    build_page_sections
  end

  def update
    if @page.update_attributes(params[:page])
      flash[:success] = "#{@page.name} was successfully saved"
      request.xhr? ? render(:json => {:status => :ok}) : redirect_to(admin_page_path(@page))
    else
      flash[:error] = 'There was a problem saving this page'
      render :edit
    end
  end

  protected
  def build_page_sections
    Grandstand::Application.page_sections.each do |page_section|
      @page.page_sections.where(:section => page_section).first || @page.page_sections.build(:section => page_section)
    end
  end

  def find_page
    return admin_not_found unless @page = Page.where(:id => params[:id]).first
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grandstand-0.2.4 app/controllers/admin/pages_controller.rb
grandstand-0.2.3 app/controllers/admin/pages_controller.rb
grandstand-0.2.2 app/controllers/admin/pages_controller.rb
grandstand-0.2.1 app/controllers/admin/pages_controller.rb