rails 3.1使用其他语言环境重新加载页面?

时间:2012-04-12 08:09:52

标签: ruby-on-rails ruby-on-rails-3.1 rails-3.1

我已按照此beautiful site在我的网站中创建国际化。

但是,当用户点击语言按钮时,我无法弄清楚如何重新加载具有不同语言环境的页面。

实施例: 如果用户在这里:

/es/events/14

当用户点击英语时重新加载

/en/events/14

这是观点:

 %li= link_to "eu", change_locale_path(:locale => "eu")
 %li= link_to "es", change_locale_path(:locale => "es")
 %li= link_to "en", change_locale_path(:locale => "en")
 %li= link_to "fr", change_locale_path(:locale => "fr")

这是ApplicationController中的方法

def change_locale
 if current_user
   current_user.locale = params[:locale]
   current_user.save
 else
   I18n.locale = params[:locale]
 end
 redirect_to root_url  (this is temporal)
end

我应该拥有什么而不​​是redirect_to root_url来重新加载页面?

1 个答案:

答案 0 :(得分:3)

- [:ru, :ua, :en].each do |locale|
  %li= link_to locale, params.merge(locale: locale)