Skip to content

Commit

Permalink
Added locales controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed Apr 6, 2009
1 parent be66c12 commit 89018d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/controllers/locales_controller.rb
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/locales_helper.rb
@@ -0,0 +1,2 @@
module LocalesHelper
end
3 changes: 2 additions & 1 deletion config/routes.rb
@@ -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
14 changes: 14 additions & 0 deletions test/functional/locales_controller_test.rb
@@ -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

0 comments on commit 89018d8

Please sign in to comment.