Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/uniquify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def uniquify(*args, &block)
options = { :length => 8, :chars => ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a }
options.merge!(args.pop) if args.last.kind_of? Hash
args.each do |name|
before_create do |record|
before_validation :on => :create do
if block
record.ensure_unique(name, &block)
ensure_unique(name, &block)
else
record.ensure_unique(name) do
ensure_unique(name) do
Array.new(options[:length]) { options[:chars].to_a[rand(options[:chars].to_a.size)] }.join
end
end
Expand Down