Permalink
Browse files

add error message capabilities (for uniqueness and length of the slug)

  • Loading branch information...
1 parent 6a3f994 commit 537f4c1ca6990148d69942af1342de055f41565a EppO committed Jan 23, 2009
Showing with 6 additions and 3 deletions.
  1. +6 −3 lib/salty_slugs.rb
View
@@ -17,14 +17,17 @@ def has_slug(*args)
prepend_id = options[:prepend_id].nil? ? true : options[:prepend_id]
sync_slug = options[:sync_slug].nil? ? false : options[:sync_slug]
scope_column = options[:scope] if options[:scope]
+ uniqueness_error_message = options[:uniqueness_error] if options[:uniqueness_error]
+ validation_error_message = options[:validation_error] if options[:validation_error]
write_inheritable_attribute :slug_column, slug_column
write_inheritable_attribute :slug_prepend_id, prepend_id
class_inheritable_reader :slug_column
class_inheritable_reader :slug_prepend_id
- validates_uniqueness_of slug_column, :scope => scope_column, :unless => :slug_prepend_id
+ validates_uniqueness_of slug_column, :scope => scope_column, :unless => :slug_prepend_id, :message => uniqueness_error_message
+ validates_length_of slug_column, :minimum => 1, :message => validation_error_message
before_validation { |record| record[slug_column] = (sync_slug || record[slug_column].blank?) ? sluggify(record.send(source_column)) : sluggify(record[slug_column]) }
end
@@ -63,8 +66,8 @@ module InstanceMethods
def to_param
return self.id if slug_prepend_id && self[slug_column].blank?
slug_prepend_id ? "#{self.id}-#{self[slug_column]}" : self[slug_column]
- end
+ end
end
end
end
-end
+end

0 comments on commit 537f4c1

Please sign in to comment.