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
0 answers

ActiveRecord `unscoped` returns models from a different database but with the same name

Update: Well, so I debugged Rails, and found out it happens because both my tables are named the same. validates_uniquness_of calls unscoped on the model's class. unscoped returns all rows from the legacy table. Original Post: I'm creating a…
0
votes
2 answers

Rails validates_uniqueness_of with unless validation on self

I'm using rails for authentication and want to validate the uniqueness of a username, unless the other username was set up as a temporary account. Example: We set up a user account that has name: "buddy" with email: "placeholder@email.com" A user…
dmt2989
  • 1,610
  • 3
  • 17
  • 30
0
votes
1 answer

sql exposure of a product over dates

I have a table with the following data ProductID StartDate EndDate TT1 1 May 2013 10 May 2013 TT1 8 May 2013 14 May 2013 TT2 6 May 2013 12 May 2013 TT2 8 May 2013 …
0
votes
1 answer

Check validates_uniqueness_of in rails for two values in or condtion

i'm having problem in checking validates_uniqueness_of which has two condtion. Class name is InviteGuest class InviteGuest < ActiveRecord::Base attr_accessible :invite_id, :email, :first_name, :last_name, :random_no validates_presence_of…
0
votes
2 answers

Rails model validation failing and it shouldn't

I have the following on my model: validates_uniqueness_of :woeid before_create :handle_woeid_issue def handle_woeid_issue Rails.logger.info 'DID ENTER HERE' #never enters here for some reason self.woeid = self.temp_woeid end def…
content01
  • 3,115
  • 6
  • 41
  • 61
0
votes
1 answer

how to use validates_uniqueness_of with condition

I'm using datamapper with ruby. I would like to validate my new data set before insert it into the table. My validation criteria are.. 1) to insert only if the field 'name' is not exist. 2) Not insert if the record with the same 'name' has already…
worrawut
  • 958
  • 10
  • 17
0
votes
2 answers

rails validates uniqueness is failing oddly

I have 2 models: class PollAnswer < ActiveRecord::Base belongs_to :poll, inverse_of: :poll_answers # Validations validates :answer, presence: true, uniqueness: { scope: :poll_id, case_sensitive: false } validates :votes_number, presence:…
0
votes
1 answer

Ignoring specific validation errors

I have Labellings which belong to Emails and Labels. Each labelling must be unique to the email/label pair - so an email can only be labelled 'test' once. I'm doing this with validates_uniqueness_of :label_id, :scope => :email_id. This works as…
nfm
  • 19,689
  • 15
  • 60
  • 90
0
votes
1 answer

Having difficulty using validates_uniqueness_of with a specific condition

My model, Goal, has these three attributes: goal_type, goal_length, and is_complete. Goal belongs_to :user. goal_type can only be "X", "Y", or "Z" goal_length can only be "short", "mid", or "long" is_complete can be true or false I want there to…
Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
0
votes
1 answer

validate_uniqueness_of scope not working

Currently I can create one item with multiple designs in unique picturelocs. Creating a second item gives me the following error that there already exists a pictureloc with that value, even though it is in a seperate item_id and shouldn't be worried…
0
votes
1 answer

Ruby on Rails - Rakefile validates_uniqueness_of

I am using a rakefile to fetch information from one website and saving it to my database. Using the TMDB-Gem, this code @movie = TmdbMovie.browse(:order_by => "release", :order => "asc", :page => 1, :per_page => 2, :language => "en",…
PMP
  • 231
  • 6
  • 25
0
votes
0 answers

how to check uniqueness of a username in MySQL database via JSON?

I have this next page, on which a user can create a new account. My question now is how can i make sure the user inserts a username that doesn't already exist in my MySQL database. The page is available on…
0
votes
1 answer

rails 3 validations uniqueness on attributes of an association

i have a model called Fund and a model called Company .. where fund belongs_to a company. i have this validation in my Fund table: validates :name, presence: true, uniqueness: true This works both on server side and client side using…
0
votes
1 answer

Rails 2.3. validates_uniqueness_of a serialized field

I have a field in a model that is serialized and when I attempted to validates the uniqueness of it, it doesn't work. (Still on Rails 2.3 on this app) app/models/foo.rb class foo < ActiveRecord::Base serialize :rules validates_uniqueness_of…
J Fong
  • 1,359
  • 1
  • 9
  • 11
0
votes
1 answer

Rspec test for object attribute uniqueness failing with undefined method 'valid?' for nil:NilClass

I have an object named "Charity" and I want to make sure that each charity has a unique name, unfortunately I'm getting the following failed test, I suspect it's a problem with my factories: Failures 1) Charity name is already taken …