<commit_before>class ApplicationController < ActionController::Base
  protect_from_forgery

  helper_method :current_user
  
  layout :dynamic_layout

  private

  def current_user
    user_id = session[:user_id]
    @current_user ||= User.find(user_id) if user_id
    # TODO: should handle unlikely case where user with that ID no longer exists
  end
  
  def authenticate_user!
    redirect_to root_path, :alert => I18n.t('messages.must_be_signed_in') unless current_user
  end
  
  # Control which layout is used.
  def dynamic_layout
    current_user.nil? ? 'welcome' : 'application'
  end
end<commit_msg>Redirect back method with optional parameters<commit_after>class ApplicationController < ActionController::Base
  protect_from_forgery

  helper_method :current_user, :redirect_to_back
  
  layout :dynamic_layout

  private

  def current_user
    user_id = session[:user_id]
    @current_user ||= User.find(user_id) if user_id
    # TODO: should handle unlikely case where user with that ID no longer exists
  end
  
  def authenticate_user!
    redirect_to root_path, :alert => I18n.t('messages.must_be_signed_in') unless current_user
  end
  
  # Control which layout is used.
  def dynamic_layout
    current_user.nil? ? 'welcome' : 'application'
  end
  
  #Redirection with optional notice
  def redirect_to_back(options = {}, default = dashboard_path)
    if has_referer?
      redirect_to :back, :notice => options[:notice]
    else
      redirect_to default, :notice => options[:notice]
    end
  end
  
  def has_referer?
    !request.env["HTTP_REFERER"].blank? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
  end
end
{'fraction_non_alphanumeric': 0.07929782082324455, 'fraction_numerical': 0.002421307506053269, 'mean_word_length': 4.086153846153846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4656782', 'n_tokens_mistral': 520, 'n_tokens_neox': 510, 'n_words': 137}