How to avoid adding the default Locale in generated URLs?

前端 未结 4 617
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 14:36

If you follow the I18N Rails Guide, all generated links contain the locale parameter (localhost/en/about, localhost/fr/about). This is because we use the method defaul

4条回答
  •  自闭症患者
    2020-12-25 15:23

    Ok I understand much better. Indeed, you almost did it.

    You just need a very useful operator in Ruby: ||

    If the first value exists, it's used, otherwise the second argument is taken into account.

    def set_locale
      I18n.locale = params[:locale] || :en
    end
    

提交回复
热议问题