-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luca Guidi
committed
Apr 6, 2009
1 parent
be66c12
commit 89018d8
Showing
4 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class LocalesController < ApplicationController | ||
before_filter :normalize_http_referer | ||
|
||
# PUT /locales/en/change | ||
def change | ||
I18n.locale = params[:id] | ||
redirect_to :back | ||
end | ||
|
||
private | ||
def normalize_http_referer | ||
request.env["HTTP_REFERER"] ||= "/" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module LocalesHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
ActionController::Routing::Routes.draw do |map| | ||
map.resources :translations, :only => [ :index ], :member => { :save => :post } | ||
map.resources :translations, :only => [ :index ], :member => { :save => :post } | ||
map.resources :locales, :only => [ ], :member => { :change => :put } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper') | ||
|
||
class LocalesControllerTest < ActionController::TestCase | ||
test "routing" do | ||
assert_routing({ :method => :put, :path => "/locales/en/change" }, | ||
:controller => "locales", :action => "change", :id => "en" ) | ||
end | ||
|
||
test "should change locale" do | ||
put :change, :id => "it" | ||
assert_redirected_to "/" | ||
assert_equal "it", I18n.locale | ||
end | ||
end |