Skip to content

Instantly share code, notes, and snippets.

@nickel
Created March 2, 2009 05:17
Show Gist options
  • Save nickel/72623 to your computer and use it in GitHub Desktop.
Save nickel/72623 to your computer and use it in GitHub Desktop.
class PagesController < ApplicationController
verify :params => :name, :only => :show, :redirect_to => :root_path
before_filter :set_locale, :ensure_valid, :only => :show
def show
render :template => "pages/#{current_page}"
end
protected
def current_page
@page ||= params[:name].to_s.downcase
end
def set_locale
I18n.locale = params[:locale]
end
def ensure_valid
unless template_exists? "pages/#{current_page}"
redirect_to root_path
end
end
end
ActionController::Routing::Routes.draw do |map|
map.page '/:locale/:name', :controller => 'pages',
:action => 'show', :requirements => { :locale => /es|en/ }
map.root_locale '/:locale', :controller => 'pages', :action => 'show',
:name => 'index', :requirements => { :locale => /es|en/ }
map.root :controller => 'pages', :action => 'show',
:name => 'index', :locale => 'es'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment