Sha256: e3cd9d6215308ae5e9204bb2c1131f489df4ce52e45cccf781f6f04e54499ff5

Contents?: true

Size: 1.73 KB

Versions: 12

Compression:

Stored size: 1.73 KB

Contents

class PagesController < InheritedResources::Base
  respond_to :js, :html
  ajax_loading
  before_filter :set_collection_name
  before_filter :parse_request_url, :only=>:show

  def set_collection_name
    if params[:page_id]
      self.resources_configuration[:self][:collection_name] = :children
    end
  end

  def parse_request_url
    if params["level1"]
      @sitemap = Sitemap.find_by_path(*[1,2,3,4].map{|i|params["level#{i}"]})
      @page = @sitemap.resource
    end
  end

  before_filter :authenticate_user!, :except=>[:show]
  before_filter :maybe_authenticate, :only=>[:show]
  before_filter :resource, :only=>[:update, :show, :destroy, :edit]
  authorize_resource

  has_scope :tagged_with, :as => :tag
  has_scope :accessible_by, :type=>:boolean, :default=>true do |c,s|
    s.accessible_by(c.current_ability)
  end

  def resource
    unless @page
      page_id = params[:id]
      if page_id.is_numeric?
        @page ||= Page.find(page_id)
      else
        @page ||= Page.where(["lower(pages.title) = ?", page_id.downcase.gsub(/[_]/, ' ')]).first
      end
      @attachments ||= @page.attachments
    end
    @page
  end

  def maybe_authenticate
    unless user_signed_in?
      authenticate_user! unless current_ability.can? :read, resource
    end
  end

  def edit
    edit! do |format|
      @attachment = Attachment.new(:page=>@page)
      @s3provider = S3Provider.new(:key=>"attachments/#{current_user.id}")
    end
  end

  def create
    create! { (@parent_page ? page_child_path(@parent_page, @page) : @page) }
  end

  def update
    update! do |format|
      if params[:child_id]
        @parent_page = @page
        @page = Page.find(params[:child_id])
        @page.parent = @parent_page
        @page.save
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
wheels-0.1.10 app/controllers/pages_controller.rb
wheels-0.1.9 app/controllers/pages_controller.rb
wheels-0.1.8 app/controllers/pages_controller.rb
wheels-0.1.7 app/controllers/pages_controller.rb
wheels-0.1.6 app/controllers/pages_controller.rb
wheels-0.1.5 app/controllers/pages_controller.rb
wheels-0.1.4 app/controllers/pages_controller.rb
wheels-0.1.3 app/controllers/pages_controller.rb
wheels-0.1.2 app/controllers/pages_controller.rb
wheels-0.1.1 app/controllers/pages_controller.rb
wheels-0.1.0 app/controllers/pages_controller.rb
wheels-0.0.49 app/controllers/pages_controller.rb