class LanguageController < ApplicationController
  def english
    I18n.locale = :en
    set_session_and_redirect
  end

  def finnish
    I18n.locale = :fin
    set_session_and_redirect
  end

  def swedish
    I18n.locale = :swe
    set_session_and_redirect
  end

  private

  def set_session_and_redirect
    session[:locale] = I18n.locale
    redirect_to request.referrer
  end
end

class LanguageController < ApplicationController
  def english
    I18n.locale = :en
    set_session_and_redirect
  end

  def finnish
    I18n.locale = :fin
    set_session_and_redirect
  end

  def swedish
    I18n.locale = :swe
    set_session_and_redirect
  end

  private

  def set_session_and_redirect
    session[:locale] = I18n.locale
    redirect_to root_path
  end
end

Make language select redirect safer
Make language select redirect safer
