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
0
votes
1 answer

Validate uniquess of association table attribute

I'm trying to achieve the following : Create a validator to be sure there is a unique album "name" per user. Please see my code below : Collaboration.rb class Collaboration < ApplicationRecord # Relations belongs_to :album belongs_to…
benoitr
  • 6,025
  • 7
  • 42
  • 67
0
votes
1 answer

I am trying to use case sensitive uniqueness on rails and the test is failing

I am currently following a Michael Hartl tutorial on ruby on rails. Every time I run a model:test it fails due to the emails uniqueness. Even though I have stated that in the model. I want to fix this before I start adding data to the web…
Mo920192
  • 39
  • 5
0
votes
1 answer

Rails uniqueness validation does not seem to be working

I have this validation rules below for my product model, and while testing the rules, I found that the uniqueness: true for :title actually does nothing. validates( :title, presence: {message: ' must be given'}, uniqueness: true ) For instance,…
Jay Jeong
  • 892
  • 2
  • 11
  • 24
0
votes
2 answers

Rails validates_uniqueness_of ignoring scope

I’m very new to Rails and am having trouble with Rails/ActiveRecord seemingly ignoring scope on a validates_uniqueness_of declaration in a project I’ve inherited. I have the following model: class User < ActiveRecord::Base … …
Jaik Dean
  • 1,109
  • 2
  • 9
  • 13
0
votes
1 answer

Ruby on Rails error when validates_uniqueness_of using collection_select

First, sorry for my bad English. I'm still learning. I have 3 tables in my DB: Problem has_many :registers has_many :solutions, through : :registers Solution has_many :problems has_many :problems, through : :registers Register belongs_to:…
0
votes
1 answer

Validates uniqueness from foreign key of foreign key

I have 3 models in my rails application, User, Course, and CourseTemplate. A Course belongs to a User and a CourseTemplate belongs to a Course. What I want to do is to validate the uniqueness between the CourseTemplate name and the User id. Is…
InesM
  • 331
  • 4
  • 16
0
votes
1 answer

Can we check the uniqueness of latitude and longitude while using gecoder gem?

Using geocoder gem in my web services , the server side we need to validate the uniqueness of location added.Is this possible with the geocoder gem, we don't want the same location twice in our database. Any help will be appreciated?
0
votes
3 answers

validates_uniqueness_of don't work

It's not some kind of synchronization problem I readed before. The code is quite simple. The model: class User < ActiveRecord::Base attr_accessor :name, :email validates_uniqueness_of :email, :on => :create, :message => "must be unique" …
wupher
  • 63
  • 1
  • 6
0
votes
1 answer

Ruby on Rails -- validating a unique record, not just unique attributes of a record

This might be a very question, but I'm trying to allow only unique records for a table called "Favorites" with attributes "lightbulb_id" and "student_id." I know about model validations class Person < ActiveRecord::Base validates_uniqueness_of…
0
votes
1 answer

Rails avoiding duplication of database entry(many attributes)

Is there any way to make the model execute an error message like flash[:notice]?? I want to avoid entering the same data to my database twice.. before_save :no_duplication private def no_duplication if CarPrice.where(:car_id =>…
0
votes
1 answer

Rails validates_uniqueness_of and scope - working only on update

I have these 3 classes: class Profile < ActiveRecord::Base end class Subject < ActiveRecord::Base end class ProfileSubject < ActiveRecord::Base belongs_to :profile belongs_to :subject validates_uniqueness_of :subject_id, scope:…
0
votes
0 answers

Use has_many :through association and accepts_nested_attributes_for on a uniqueness validation

Is it possible using accepts_nested_attributes_for in a has_many through: association to create children only if not duplicates. Otherwise create only the relationship in the join table? I have a List which can have many Email. The inverse is…
0
votes
1 answer

in rails, how to validate a fields which is NOT uniqueness?

can i have a validation which do exactly opposite to validates_uniqueness_of? i.e. i would like to show a error message when the user input is NOT exist in database. thanks all. :)
Victor Lam
  • 3,646
  • 8
  • 31
  • 43
0
votes
1 answer

Phalcon PHP: test Uniqueness on a natural key?

I've got some code like this: $this->validate(new \Phalcon\Mvc\Model\Validator\Uniqueness(['field' => $field])); if (true == $this->validationHasFailed()) { throw new SpecialInternalUniqueException(); } This works for all columns except for…
Mr Mikkél
  • 2,577
  • 4
  • 34
  • 52
0
votes
1 answer

Rspec testing of validates_uniqueness_of passes when it should fail

I'm fairly new to Rspec testing and this is very frustrating. I have a model which uses validates_uniqueness_of to prevent duplicate entries from being created. (I know that this is not guaranteed and the preferred way is to use database level…
Adam
  • 518
  • 7
  • 17