<commit_before>class BathroomsController < ApplicationController
  helper :bathrooms

  before_filter :list_bathrooms, only: [:index, :list, :nearby]
  before_filter :find_bathroom, only: [:show, :update, :edit, :destroy, :up_vote, :down_vote]

	def list
		render json: @bathrooms
	end

  def nearby
    render layout: false
  end

  def guess
    @bathroom = Bathroom.new(permitted_params)
    @bathroom.reverse_geocode
    render 'new', layout: false
  end

  def new
    @bathroom = Bathroom.new
  end

  def create
    @bathroom = Bathroom.new(permitted_params)

    if @bathroom.save
      flash[:notice] = I18n.t('bathroom.flash.new', name: @bathroom.name)
      redirect_to @bathroom
    else
      display_errors
      render 'new'
    end
  end

  def update
    if @bathroom.update(permitted_params)
      flash[:notice] = I18n.t('bathroom.flash.updated')
      redirect_to @bathroom
    else
      display_errors
      render 'edit'
    end
  end

  def destroy
    if @bathroom.destroy
      flash[:notice] = I18n.t('bathroom.flash.deleted')
      redirect_to bathrooms_path
    else
      display_errors
      redirect_to @bathroom
    end
  end

  def down_vote
    @bathroom.downvote!

    if @bathroom.save
      flash[:notice] = I18n.t('bathroom.flash.downvotesuccess')
      redirect_to @bathroom
    else
      flash[:alert] = I18n.t('bathroom.flash.downvoteerror')
      redirect_to @bathroom
    end
  end

  def up_vote
    @bathroom.upvote!

    if @bathroom.save
      flash[:notice] = I18n.t('bathroom.flash.upvotesucess')
      redirect_to @bathroom
    else
      flash[:alert] = I18n.t('bathroom.flash.upvoteerror')
      redirect_to @bathroom
    end
  end

private

  def list_bathrooms
    @bathrooms = Bathroom.all.page(params[:page])

    @bathrooms = if params[:search].present? || params[:map] == "1"
      @bathrooms.near([params[:lat], params[:long]], 20, :order => 'distance')
    else
      @bathrooms.reverse_order
    end
  end

  def display_errors
    if @bathroom.errors.any?
      errors = @bathroom.errors.each do |attribute, message|
        flash[:alert] = I18n.t('bathroom.flash.field')
      end
    else<commit_msg>Use update_attributes in BathroomsController#up_vote and down_vote<commit_after>class BathroomsController < ApplicationController
  helper :bathrooms

  before_filter :list_bathrooms, only: [:index, :list, :nearby]
  before_filter :find_bathroom, only: [:show, :update, :edit, :destroy, :up_vote, :down_vote]

	def list
		render json: @bathrooms
	end

  def nearby
    render layout: false
  end

  def guess
    @bathroom = Bathroom.new(permitted_params)
    @bathroom.reverse_geocode
    render 'new', layout: false
  end

  def new
    @bathroom = Bathroom.new
  end

  def create
    @bathroom = Bathroom.new(permitted_params)

    if @bathroom.save
      flash[:notice] = I18n.t('bathroom.flash.new', name: @bathroom.name)
      redirect_to @bathroom
    else
      display_errors
      render 'new'
    end
  end

  def update
    if @bathroom.update(permitted_params)
      flash[:notice] = I18n.t('bathroom.flash.updated')
      redirect_to @bathroom
    else
      display_errors
      render 'edit'
    end
  end

  def destroy
    if @bathroom.destroy
      flash[:notice] = I18n.t('bathroom.flash.deleted')
      redirect_to bathrooms_path
    else
      display_errors
      redirect_to @bathroom
    end
  end

  def down_vote
    if @bathroom.update_attributes downvote: @bathroom.downvote + 1
      flash[:notice] = I18n.t('bathroom.flash.downvotesuccess')
    else
      flash[:alert] = I18n.t('bathroom.flash.downvoteerror')
    end
    redirect_to @bathroom
  end

  def up_vote
    if @bathroom.update_attributes upvote: @bathroom.upvote + 1
      flash[:notice] = I18n.t('bathroom.flash.upvotesucess')
    else
      flash[:alert] = I18n.t('bathroom.flash.upvoteerror')
    end
    redirect_to @bathroom
  end

private

  def list_bathrooms
    @bathrooms = Bathroom.all.page(params[:page])

    @bathrooms = if params[:search].present? || params[:map] == "1"
      @bathrooms.near([params[:lat], params[:long]], 20, :order => 'distance')
    else
      @bathrooms.reverse_order
    end
  end

  def display_errors
    if @bathroom.errors.any?
      errors = @bathroom.errors.each do |attribute, message|
        flash[:alert] = I18n.t('bathroom.flash.field')
      end
    else
{'fraction_non_alphanumeric': 0.10652920962199312, 'fraction_numerical': 0.009163802978235968, 'mean_word_length': 3.020257826887661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1443953', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1523, 'n_words': 318}