2013-04-04 40 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軌道和許多其他)自動包含區域設置參數。