Sha256: ebc609330bddb93137a4bf196a5e63ca144c9f214b732c15aa15e6b7dc011734

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 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
  helper_method :home_page?
  
  protected
  
  def current_locale
    I18n.locale.to_s
  end
  
  def home_page?
    current_page?( Fullstack::Cms.localized? ? url_for([:site, :home, I18n.locale]) : url_for([:site, :home])  )
  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.23 lib/generators/fullstack/cms/templates/rails/app/controllers/site/site_controller.rb