validates_duplicity_of
ActiveRecord (>= 3) callback which handle the name duplication in your model with ease. Ruby 2 only!
Example :
Untilted File > Untilted File (1) > Untilted File (2) …
Installation
Add this line to your application's Gemfile:
gem 'validates_duplicity_of'
And then execute:
$ bundle
Or install it yourself as:
$ gem install validates_duplicity_of
Usage
Use method validates_duplicity_of with attribute in your Rails model. Scope is optional.
class Post
validates_duplicity_of :name, scope: :user_id
end
p = Post.create name: "Foo", user_id: 1
p.name
=> "Foo"
p = Post.create name: "Foo", user_id: 1
p.name
=> "Foo (1)"
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request