1

I have a question about redirectin request with parameters.

I have a language button in my ruby on rails application. User can see the site in spanish if he desires. I have the following piece of code to change the language.

application_controller.rb

  def set_locale

    session[:selected_locale] = params[:lang].nil? ?   session[:selected_locale] : params[:lang]

    I18n.locale = session[:selected_locale] || I18n.default_locale

  end

When user wants to see the site in spanish, he clicks the relatin button and I redirect the request to the home page with /lang=en parameters. However, when the language changes and user is redirected to the home page, url seems to stay like ..../?lang=es.

How can I ensure that url is stripped form ?lang=es parameters. I know I can do it using javascript with the "window.location.href = '';" code, but I want to find a easier way,

Thanks.

Hilmi Yamcı
  • 463
  • 8
  • 20
  • Use an instance variable instead of passing params into query string. – Timmy Von Heiss Aug 27 '17 at 22:39
  • When user want to change language, they click language button, it will redirect to example.com?lang=en. After that, you want to redirect to example.com, is that correct? – Tai Aug 28 '17 at 09:16
  • Yeap, that's what I'm trying to do – Hilmi Yamcı Aug 28 '17 at 11:10
  • Possible duplicate of [How to remove blank values params from query string](https://stackoverflow.com/questions/11102379/how-to-remove-blank-values-params-from-query-string) – Joseph Cho Oct 21 '17 at 18:58

0 Answers0