Sha256: 65864e3dd711d17fd0b03e1d1c422af32a1ef0d6ff998b2a809e7600b0a6da1f

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class Site::SiteController < ApplicationController
  include Pageable
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  authorize :scope => "site", :resourceful => false
  prepend_before_filter(:set_locale) if Fullstack::Cms.localized?
    
  # =========
  # = Pages =
  # =========
  
  page :home, "/" do
  end
  
  # ===========
  # = Helpers =
  # ===========
  
  helper_method :current_locale
  
  protected
  
  def current_locale
    I18n.locale.to_s
  end
  
  # ===================
  # = Private Methods =
  # ===================
  
  private
  
  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
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fullstack-cms-0.2.22 lib/generators/fullstack/cms/templates/rails/app/controllers/site/site_controller.rb