Questions tagged [validates-uniqueness-of]

validates_uniqueness_of is a rails helper method for determining whether an attribute is unique throughout a system

In Ruby on Rails, the validates_uniqueness_of method determines whether an attribute is unique across a system.

http://apidock.com/rails/v4.2.1/ActiveRecord/Validations/ClassMethods/validates_uniqueness_of

94 questions
2
votes
1 answer

Rails: Append number to permalink, if permalink already taken

I would like to give John Doe the permalink john-doe-2, if there already is a john-doe-1. The number should be the next free one to be appended ("john-doe-n") Currently my permalinks are generated the usual way: before_validation :generate_slug …
David
  • 937
  • 1
  • 12
  • 22
2
votes
1 answer

validates_uniqueness_of failing with tests, machinist

I have a validates_uniqueness_of validation on my model: #SwimMeetRelayEvent.rb validates_uniqueness_of :event_number_digit, :scope => [:swim_meet_id, :event_number_alpha] validates_uniqueness_of :event_number_alpha, :scope => [:swim_meet_id,…
2
votes
1 answer

Reservation Type System w/ Validation - Rails 3.0

What would be the best approach to trying to "validate" uniqueness of dates for object. -- So for example, I have a Room, that can only have 1 person in it at a time. A User can book this Room in advance. Currently the Room is booked from the 1st of…
fighella
  • 580
  • 5
  • 16
2
votes
1 answer

Efficiency of uniqueness validation in Active Record Rails

Which is more efficient while creating records with unique values for a column in rails Placing uniqueness validation vs finding if record exists with same value and create based on the existence. Which is more efficient in terms of coding and…
2
votes
3 answers

Rails Models Validation 1 Word

I try to add a validation from a blog category only limited at 1 word. But I try this length: { maximum: 1 } I doesn't work. Is there a validation to validaes only one word and not uniqueness? Thank you for your answers
Hussein.
  • 179
  • 2
  • 11
2
votes
1 answer

Rspec ignores uniqueness validation

I don't want rspec to let me save two objects of the class with the same name, however it does. Is there something I'm missing? My model: class Product < ActiveRecord::Base validates :title, :description, :image_url, presence: true validates…
mohnstrudel
  • 639
  • 8
  • 22
2
votes
1 answer

Rails accepts_nested_attributes for: eliminating duplicates

Say we've got the following models: class User < ActiveRecord::Base has_many :widgets accepts_nested_attributes_for :widgets, allow_destroy: true end class Widget < ActiveRecord::Base belongs_to :user validates :title, presence:…
scttnlsn
  • 2,976
  • 1
  • 33
  • 39
2
votes
1 answer

Validating unique project names in Ruby on Rails for a single user

In my model class Project, I wish to create projects with a name. I validate the name like this: validates :name, :uniqueness => true I would like the name for the projects to be unique, only in the scope of a User. Meaning, a user cannot have…
user1121487
  • 2,662
  • 8
  • 42
  • 63
2
votes
1 answer

Validating arraycollection in symfony2

I'm new to Symfony2 + Doctrine and I´m looking for a way to validate the uniqueness in an Arraycollection. May be it is already answered question but I can´t figure how resolve it. I`ve a Relevamientosserviciosprestador class with a…
2
votes
1 answer

Rails Validates_uniqueness of scope not working

My validations raise an "Email already taken" error on the create method. I have this validation in my Customer model: validates :email, :uniqueness => {:scope => :account_id, :case_sensitive => false} and this is what I'm seeing in my…
1
vote
1 answer

Rails: validates uniqueness through

I have the following Models: Language Itemtype Item belongs_to :itemtype LocalisedItem belongs_to :item belongs_to :language The LocalisedItem model has an attribute called "title". I want to validate the uniqueness of said "title"…
Majiy
  • 1,890
  • 2
  • 24
  • 32
1
vote
1 answer

Getting ActiveRecord::RecordNotUnique but then not able to find the existing record

I have something like the following code. (Model names changed as they're not important to what's happening.) The #find_or_create_bar_for_blah_id works fine most of the time. Occasionally it will return nil though and I'm not sure why. It's some…
1
vote
3 answers

skip validation_uniqueness for certain values

I have validation on uniqueness and I want skipping certain value or values(for example 0000): validates_uniqueness_of :gtin, :scope => [:user_id, :item_id] I'm tried to use next construction, but she don't work: validates_uniqueness_of :gtin,…
1
vote
0 answers

Rails: Validation unique friendship

I have a User model and a Catpanion (friend) model. The catpanion model is self-referrential connecting two users together with a requestor_id and a requestee_id through an add friend system. I'm trying to validate that two users are not already…
1
vote
1 answer

Rail Model: Using validates_uniqueness_of with scope on attributes of associated entity?

I have Model defined as below class One 'map__ones__twos'} } class Two