Created
March 2, 2009 05:17
-
-
Save nickel/72623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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