2013-04-04 42 views
1

我已经得到了我的大部分网站在locales(i18n)下工作。但是,现在我正在管理端工作。这在任何地方都行不通。我刚刚意识到,每个不属于本地范围的URL都在URL末尾附加了“?locale = en”。我的网址附有这个“?locale = en”。这是正常的吗?

你可以看看这个网站。每个网址似乎都很好。但是,如果您转到可将您带回到根目录的左上角图标,则会将该位添加到URL中。 http://hik-fyp.heroku.com

我想这是显示某种语言的根。但是,当涉及到管理部分(这是单语)时,它显示无处不在。

这是正常的吗?这可能会干扰网站?有没有办法摆脱它? 我花了一段时间在网上进行研究,但找不到类似的东西。在此先感谢...

这是从的ApplicationController

一个提取
after_filter :store_location 
    before_filter :set_locale 




    def set_locale 
    logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}" 
    I18n.locale = params[:locale] || extract_locale_from_accept_language_header || I18n.default_locale 
    logger.debug "* Locale set to '#{I18n.locale}'" 
    if current_user 
     current_user.locale = params[:locale] 
     current_user.save 
    end 
    session[:locale] = I18n.locale 
    end 


    def default_url_options(options={}) 
    logger.debug "default_url_options is passed options: #{options.inspect}\n" 
    { :locale => I18n.locale } 
    end 


    def store_location 
    # store last url as long as it isn't a /users path 
    session[:previous_url] = request.fullpath unless request.fullpath =~ /\/users/ 
    end 

    def after_sign_in_path_for(resource) 
    session[:previous_url] || root_path 
    end 

回答

0

你定义,当你设置发生

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

这告诉url_for助手(它underlies的link_to轨道和许多其他)自动包含区域设置参数。