In a test app, I have a drop-down selection to change the language of
the site.
I use an Ajax request to an action in which the locale is changed, and
the it's redirected to the home page
unfortunately, the locale seems to be changed but the home page
doesn't reflect the new language ..

application_controller.rb
..  before_filter :set_locale
  def set_locale
    I18n.locale = params[:locale]
  end

  def default_url_options(options={})
    {:locale => I18n.locale}
  end


jquery Ajax request in  application.js

jQuery(document).ready(function() {
  //    handle change events from language selector
  $("select[id^='language_']").change(function(event) {
    var selected = $("#" + event.target.id + " option:selected");
    var value =  selected.val();
    $.ajax({
      data: 'locale='+ value,
      type: 'post',
      url: '/locale'
      });
  });
});

routes.rb
  match '/locale'  => "welcome#switch_language"

welcome_controller.rb
..
  def switch_language
    I18n.locale = params[:locale].to_sym
    redirect_to root_url
  end

what could be wrong ?

thanks fyh

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to