<commit_before># frozen_string_literal: true

# Allows models with an id:integer and a slug:string to be found by either using
# find_by_param, and by overriding to_param for URL generation.
module Sluggable
  extend ActiveSupport::Concern

  included do
    def self.find_by_param(input)
      find_by "#{table_name}.slug = ? or #{table_name}.id = ?", input.to_param.to_s, input.to_param.to_i
    end
  end

  def to_param
    slug.blank? ? id.to_s : slug
  end
end<commit_msg>Sluggable should use "slug_was" to avoid creating url for another database object<commit_after># frozen_string_literal: true

# Allows models with an id:integer and a slug:string to be found by either using
# find_by_param, and by overriding to_param for URL generation.
module Sluggable
  extend ActiveSupport::Concern

  included do
    def self.find_by_param(input)
      find_by "#{table_name}.slug = ? or #{table_name}.id = ?", input.to_param.to_s, input.to_param.to_i
    end
  end

  def to_param
    slug_was.blank? ? id.to_s : slug_was
  end
end
{'fraction_non_alphanumeric': 0.08139534883720931, 'fraction_numerical': 0.0, 'mean_word_length': 4.063725490196078, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2991935', 'n_tokens_mistral': 358, 'n_tokens_neox': 346, 'n_words': 106}