<commit_before>class MealsController < ApplicationController
  load_and_authorize_resource

  def index
    load_meals
  end

  def work_calendar
    authorize!(:read, Meal)
    params[:uid] = current_user.id unless params.has_key?(:uid)
    @users = User.all
    load_meals
  end

  def show
    @signup = Signup.for(current_user, @meal)
    load_prev_next_meal
  end

  def new
    @meal = Meal.new_with_defaults
    @min_date = Date.today.strftime("%Y-%m-%d")
    prep_form_vars
  end

  def edit
    @meal = Meal.find(params[:id])
    @min_date = nil
    prep_form_vars
  end

  def create
    if @meal.save
      flash[:success] = "Meal created successfully."
      redirect_to meals_path
    else
      set_validation_error_notice
      prep_form_vars
      render :new
    end
  end

  def update
    if @meal.update_attributes(meal_params)
      flash[:success] = "Meal updated successfully."
      redirect_to meals_path
    else
      set_validation_error_notice
      prep_form_vars
      render :edit
    end
  end

  protected

  def default_url_options
    {mode: params[:mode]}
  end

  private

  def load_meals
    @meals = Meal.future.oldest_first
    @meals = @meals.worked_by(User.find(params[:uid])) if params[:uid].present?<commit_msg>2863: Fixed controller to use ability<commit_after>class MealsController < ApplicationController
  load_and_authorize_resource

  def index
    load_meals
  end

  def work_calendar
    authorize!(:read, Meal)
    params[:uid] = current_user.id unless params.has_key?(:uid)
    @users = User.all
    load_meals
  end

  def show
    @signup = Signup.for(current_user, @meal)
    load_prev_next_meal
  end

  def new
    @meal = Meal.new_with_defaults
    @min_date = Date.today.strftime("%Y-%m-%d")
    prep_form_vars
  end

  def edit
    @meal = Meal.find(params[:id])
    @min_date = nil
    prep_form_vars
  end

  def create
    if @meal.save
      flash[:success] = "Meal created successfully."
      redirect_to meals_path
    else
      set_validation_error_notice
      prep_form_vars
      render :new
    end
  end

  def update
    if @meal.update_attributes(meal_params)
      flash[:success] = "Meal updated successfully."
      redirect_to meals_path
    else
      set_validation_error_notice
      prep_form_vars
      render :edit
    end
  end

  protected

  def default_url_options
    {mode: params[:mode]}
  end

  private

  def load_meals
    @meals = @meals.future.oldest_first
    @meals = @meals.worked_by(User.find(params[:uid])) if params[:uid].present?
{'fraction_non_alphanumeric': 0.08267716535433071, 'fraction_numerical': 0.0015748031496062992, 'mean_word_length': 2.9212962962962963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1668520', 'n_tokens_mistral': 892, 'n_tokens_neox': 846, 'n_words': 188}