From e98e329d920887f18d1741cddf344d01ab7fcae3 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 21 Feb 2013 16:43:20 -0500 Subject: [PATCH] be ok when there are no existing slugs --- README.md | 8 ++++++++ lib/formtastic-slug/slug_input.rb | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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