diff --git a/README.md b/README.md index c3f4215..589bc15 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ Add a slug field, that generates a slug based on another field. = f.input :slug, :as => :slug, :based_on => :title ``` +You can put in the list of existing slugs and the editor will avoid using those: + +``` haml += semantic_form_for @blog_entry do |f| + = f.input :title + = f.input :slug, :as => :slug, :based_on => :title, :existing_slugs => @blog_entry.class.slugs +``` + Just add it to your Gemfile: ``` ruby diff --git a/lib/formtastic-slug/slug_input.rb b/lib/formtastic-slug/slug_input.rb index 8184d8f..d45b7cf 100644 --- a/lib/formtastic-slug/slug_input.rb +++ b/lib/formtastic-slug/slug_input.rb @@ -34,6 +34,10 @@ class SlugInput < Formtastic::Inputs::StringInput target_method_name.to_s.gsub(/[\?\/\-]$/, '') end + def existing_slugs + options[:existing_slugs] || [] + end + def slug_js_setup (<<-JS).html_safe