Sha256: 22ce50cb483917d7905f48ebdeb027772170ca602d43888df6be4b7954c4d8ce

Contents?: true

Size: 1.05 KB

Versions: 26

Compression:

Stored size: 1.05 KB

Contents

class PagesController < CmsController
  before_filter :find_page, only: :show

  private

  def find_page
    root = ActiveadminSelleoCms::Page.root

    raise "Create at least one page" unless root

    page_id = nil

    5.downto(1).each do |l|
      if params["slug#{l}"] and page = ActiveadminSelleoCms::Page.where(parent_id: page_id).find_by_slug(params["slug#{l}"])
        page_id = page.id
      end
    end

    @page = ActiveadminSelleoCms::Page.find_by_id(page_id)

    if !@page or (!@page.is_published? and @page != root)
      redirect_to page_path(I18n.locale, root)
    elsif @page.redirect_to_first_sub_page
      redirect_to page_path(I18n.locale, @page.children.first || root)
    elsif @page.is_link_url
      redirect_to @page.link_url
    end
  end

  public

  def show
    @page.update_column(:views, (@page.views || 0) + 1)
    render action: :show, layout: @page.layout_name
  end

  def index
    respond_to do |format|
      format.html { redirect_to page_path(I18n.locale, ActiveadminSelleoCms::Page.root) }
      format.json
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
activeadmin-selleo-cms-0.0.61 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.60 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.59 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.58 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.54 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.52 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.51 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.49 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.48 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.47 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.46 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.45 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.44 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.43 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.42 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.41 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.40 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.39 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.38 app/controllers/pages_controller.rb
activeadmin-selleo-cms-0.0.37 app/controllers/pages_controller.rb