Sha256: 78e5d69ce6c17a4e3f6dd5a01f6ccfa925b2cc6e57e6f609a94e24dae2bb356c

Contents?: true

Size: 1.73 KB

Versions: 35

Compression:

Stored size: 1.73 KB

Contents

class Site::BaseController < ApplicationController
  include Pageable
  include Sitemap
  include Deny

  prepend_before_filter(:set_locale) if Fullstack::Cms.localized?

  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  rescue_from DeniedError, :with => :handle_unauthorized
  rescue_from PageNotFoundError, :with => :render_404

  # ===========
  # = Helpers =
  # ===========

  helper_method :current_locale
  helper_method :current_locale?
  helper_method :logged_in?
  helper_method :guest?

  protected
  def current_locale
    I18n.locale.to_s
  end

  def current_locale?(locale)
    current_locale == locale.to_s
  end

  def set_locale
    I18n.locale = "#{params[:locale]}".to_sym if params[:locale]
    render_404 if I18n.locale.nil? || !I18n.available_locales.include?(I18n.locale.to_sym)
  end

  def instantiate_resource_by_slug!(resource)
    res = resource.find_by_slug!(params[:slug])
    instance_variable_set("@#{resource.name.underscore}", res)
    @object = res
    res
  end

  alias :resource_by_slug! :instantiate_resource_by_slug!

  def instantiate_resource_by_slug_and_locale!(resource)
    res = resource.find_by_slug_and_locale!(params[:slug], current_locale)
    instance_variable_set("@#{resource.name.underscore}", res)
    @object = res
    res
  end

  alias :resource_by_slug_and_locale! :instantiate_resource_by_slug_and_locale!

  def render_404
    render :file => Rails.root.join("public", "404.html"), :layout => false, :status => :not_found
  end

  def handle_unauthorized
    if guest?
      redirect_to new_user_session_path
    else
      render_404
    end
  end

  def render_404!
    raise PageNotFoundError.new
  end

  def guest?
    !current_user
  end

  def logged_in?
    current_user
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fullstack-cms-0.4.6 app/controllers/site/base_controller.rb
fullstack-cms-0.4.5 app/controllers/site/base_controller.rb
fullstack-cms-0.4.4 app/controllers/site/base_controller.rb
fullstack-cms-0.4.3 app/controllers/site/base_controller.rb
fullstack-cms-0.4.2 app/controllers/site/base_controller.rb
fullstack-cms-0.4.1 app/controllers/site/base_controller.rb
fullstack-cms-0.3.39 app/controllers/site/base_controller.rb
fullstack-cms-0.3.38 app/controllers/site/base_controller.rb
fullstack-cms-0.3.37 app/controllers/site/base_controller.rb
fullstack-cms-0.3.36 app/controllers/site/base_controller.rb
fullstack-cms-0.3.35 app/controllers/site/base_controller.rb
fullstack-cms-0.3.34 app/controllers/site/base_controller.rb
fullstack-cms-0.3.33 app/controllers/site/base_controller.rb
fullstack-cms-0.3.32 app/controllers/site/base_controller.rb
fullstack-cms-0.3.31 app/controllers/site/base_controller.rb
fullstack-cms-0.3.30 app/controllers/site/base_controller.rb
fullstack-cms-0.3.29 app/controllers/site/base_controller.rb
fullstack-cms-0.3.28 app/controllers/site/base_controller.rb
fullstack-cms-0.3.27 app/controllers/site/base_controller.rb
fullstack-cms-0.3.26 app/controllers/site/base_controller.rb